I am getting a permissions issue when running django in daemon mode. Reading here https://code.google.com/p/modwsgi/wiki/ConfigurationIssues#Location_Of_UNIX_Sockets I think the solution is to configure the WSGISocketPrefix
The problem is that /var/run/wsgi is no where to be found on my centos server.
The closes thing I can find is: /etc/httpd/run/httpd.pid
How can I find where wsgi is installed?
Or what other value can I set the WSGISocketPrefix equal to?
With Ubuntu 14.0.4 LTS, Django11.1, Python 3.6.1, and mod_wsgi-4.5.15 it works for me as follows:
Apache was showing the following error:
503 Service Unavailable
Apache error log showed the following:
[wsgi:error] [pid 5411] (2)No such file or directory: [client 1.2.3.4:12345] mod_wsgi (pid=5411): Unable to connect to WSGI daemon process 'mywsgi' on '/var/run/apache2/wsgi.5403.0.1.sock' as user with uid=123.
Note that I'm running WSGI as a different user than the default www-data. This is changed with 'user' from WSGIDaemonProcess.
Solution:
At the bottom of /etc/apache2/apache2.conf, add:
WSGISocketPrefix /var/run/apache2/wsgi
After restarting Apache, I can ls -la and see the lock files under /var/run/apache2:
apache2.pid
wsgi.5017.0.1.sock
Sources:
http://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGISocketPrefix.html?highlight=WSGISocketPrefix%20
https://code.google.com/archive/p/modwsgi/wikis/ConfigurationIssues.wiki#Location_Of_UNIX_Sockets
Related
Problem
I am running apache2 on my local ubuntu server. I set up a Django project using django-admin startproject site and set up my virtual host to use a WSGI Daemon process to run the Django project. This worked and the site is accessible through its IP 192.168.1.3.
When I go to /admin, it allows me to log in and see the initial backend but loads for 5 minutes then goes to a 500 error when I click anything or reload, even when trying to access the non-admin index page. This persists until I run systemctl restart apache2 and completely restart apache or wait ~10-15 minutes until it fixes itself (only to break again immediately if I access /admin pages).
Versions
Django version 4.1.5
mod-wsgi version 4.9.4
My Attempts
If I run the project with python manage.py runserver, I can access it on 192.168.1.3:8000 and fully use the /admin backend, even creating new users, etc. I then thought it was the WSGI Daemon process somehow messing it up, so I followed the linked section of this page: https://pypi.org/project/mod-wsgi#using-mod-wsgi-express-with-django and ran the site with python manage.py runmodwsgi. The site completely works on 192.168.1.3:8000 along with the /admin, and I can create new users etc., which points to it having nothing to do with the WSGI setup (as well as the non-admin pages working fine on the virtual host WSGI).
I have fully deleted and restarted the Django project, as well as setting up new virtual host .conf files with the proper WSGI information, etc.
I read about an /admin loading issue back in Django 3.0, but I am on 4.1 so that is unrelated.
I am at a complete loss at what the issue could be at this point. Why won't my /admin section work on the virtual host??
EDIT:
The issue is actually definitely the WSGI somehow. I am getting this is my apache error log:
[Sun Jan 29 09:27:12.388714 2023] [wsgi:error] [pid 67623:tid 140212873184832] (70007)The timeout specified has expired: [client 192.168.1.10:63055] mod_wsgi (pid=67623): Failed to proxy response from daemon., referer: http://192.168.1.3/admin/
[Sun Jan 29 09:27:14.427470 2023] [wsgi:error] [pid 67624:tid 140211782657600] [client 192.168.1.10:63053] Timeout when reading response headers from daemon process 'Portfolio': /var/www/Portfolio/Portfolio/wsgi.py, referer: http://192.168.1.3/admin/auth/
[Sun Jan 29 09:27:14.949762 2023] [wsgi:error] [pid 67624:tid 140211279357504] [client 192.168.1.10:63056] Timeout when reading response headers from daemon process 'Portfolio': /var/www/Portfolio/Portfolio/wsgi.py, referer: http://192.168.1.3/admin/auth/
[Sun Jan 29 09:27:16.385674 2023] [wsgi:error] [pid 67623:tid 140212856399424] [client 192.168.1.10:63100] Truncated or oversized response headers received from daemon process 'Portfolio': /var/www/Portfolio/Portfolio/wsgi.py
I still do not know what the solution is, though.
https://forum.djangoproject.com/t/django-apache-deployment-not-working-as-intended/15800
I found the solution. Somehow during the whole setup, adding WSGIApplicationGroup %{GLOBAL} to the /etc/apache2/apache2.conf file was never recommended, at least not that I noticed, but it worked and all the admin functionality works on the virtual host through WSGI Daemon.
Hope this can help someone else.
Please help me to set my home PC as a server (Windows 10 + Python + Django + Postgre SQL + Anaconda)
There are several instructions on how to set the server on the Internet, and surprisingly, many instructions differ from each other. I have absolutely no experience in setting a server. Probably, I’m making a stupid mistake somewhere that I can’t identify for 3 days. I am lost.
I believe that most useful instructions are these (they are complete and new):
https://www.codementor.io/aswinmurugesh/deploying-a-django-application-in-windows-with-apache-and-mod_wsgi-uhl2xq09e
https://ostrokach.gitlab.io/post/apache-django-anaconda/
I followed the instructions and successfully downloaded the necessary modules, installed Wamp, made the changes as displayed in the guide and started it. What I see now: the Wamp icon glows green. When I load a localhost, the page loads endlessly but does not load.
Wamp error log shows following: [Fri Oct 11 14:50:33.823752 2019]
[core:notice] [pid 1364:tid 808] AH00094: Command line:
'c:\wamp64\bin\apache\apache2.4.39\bin\httpd.exe -d
C:/wamp64/bin/apache/apache2.4.39' [Fri Oct 11 14:50:33.840681 2019]
[mpm_winnt:notice] [pid 1364:tid 808] AH00418: Parent: Created child
process 15052 [Fri Oct 11 14:50:34.981629 2019] [mpm_winnt:notice]
[pid 15052:tid 800] AH00354: Child: Starting 64 worker threads.
Project name: turiumasina
path D:/Users/PycharmProjects/turiumasina/
path to wsgi:D:/Users/PycharmProjects/turiumasina/turiumasina/wsgi_windows.py (I renamed wsgi to wsgi_windows, settings file is in turiumasina/turiumasina/)
I copied the output generated by the mod_wsgi-express command and pasted it at the end of C:\wamp64\bin\apache\apache\conf\httpd.conf
my httpd-vhosts.conf
ServerName localhost
WSGIPassAuthorization On
ErrorLog "logs/turiumasina.error.log"
CustomLog "logs/turiumasina.access.log" combined
WSGIScriptAlias / "D:/Users/PycharmProjects/turiumasina/turiumasina/wsgi_windows.py"
<Directory "D:/Users/PycharmProjects/turiumasina">
<Files wsgi_windows.py>
Require all granted
</Files>
</Directory>
Alias /static "D:/Users/PycharmProjects/turiumasina/static"
<Directory "D:/Users/PycharmProjects/turiumasina/static">
Require all granted
</Directory>
wsgi_windows.py
import os
import sys
import site
from django.core.wsgi import get_wsgi_application
site.addsitedir("C:/users/.conda/envs/turiumasina/Lib/site-packages")
sys.path.append('D:/Users/PycharmProjects/turiumasina')
sys.path.append('D:/Users/PycharmProjects/turiumasina/turiumasina')
os.environ['DJANGO_SETTINGS_MODULE'] = 'turiumasina.settings'
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "turiumasina.settings")
application = get_wsgi_application()
I generated the "static" folder, wrote a line in the settings.py:
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
If I enter python manage.py runserver via pycharm, I can see my site through a browser (http://127.0.0.1:8000/). the Wamp icon glows green. When I load a localhost, the page loads endlessly but does not load.
I would like my site to be visible not only to me, but also to Internet users by entering my external IP.
If you need, I can send you the whole project and project settings
I would get rid of WAMP altogether, I don't see why you need it if you're not using PHP or MySql.
If you just need to play/debug the Django app over the local network just run ./manage.py runserver 0.0.0.0:8000 (or any other port). Make sure your Windows firewall is allowing incoming connections to the port.
The connect to it you need the computer's actual IP not '0.0.0.0:8000'. Type 'ipconfig' at the command prompt to see what your actual IP is an then connect to Your_actual_IP:8000
If you need something more solid than the build-in Django server (to run in non-debug mode) then you can install Waitress (https://docs.pylonsproject.org/projects/waitress/en/latest/).
I installed Apache and mod_wsgi on Win 7 and copied config text output of mod_wsgi into httpd.conf.
I also check and see server working before mod_wsgi.
Now when I try to connect on local host I get a connection refused. After some research I found out I should add mod_wsgi.server to my app settings. I did it and ran runmodwsgi which failed because it was running a script in Windows which used os.getuid. Not valid in Windows. Is it mandatory to add mod_wsgi to isntalled apps in django project? Not mentioned in here.
If so what can I do for os.getuid in Windows?
Beside these why I get connection refused and no log if only my handler config is incorrect.
I ran httpd from cmd and found the error:
[Fri Dec 21 10:11:17.538864 2018] [wsgi:info] [pid 64084:tid 180]
mod_wsgi (pid=64084): Initializing Python. Fatal Python error:
Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Don't know the reason yet.
[UPDATE]
Changed PYTHONHOME to python base path and it is working now. There most be an in compatibility between venv and setuptools.
I'm with a problem while deploying Django in my VPS with Centos 7.3 and WHM. It seems to work, except for a socket problem with mod_wsgi.
[Sun Jun 25 00:37:03.254774 2017] [wsgi:error] [pid 29756] (13)Permission denied: [client 66.249.83.220:35523] mod_wsgi (pid=29756): Unable to connect to WSGI daemon process 'brunamaiahair.com.br' on '/var/run/apache2/wsgi.721.27.1.sock' as user with uid=1004.
I read to insert WSGISocketPrefix as a directive, so I edited httpd.conf and put:
WSGISocketPrefix /var/run/apache2/wsgi
But I'm receiving the same error. Here is the log with the modified httpd.conf after an Apache restart:
[Sat Jun 24 21:10:56.084269 2017] [mpm_prefork:notice] [pid 721] AH00163: Apache/2.4.25 (cPanel) OpenSSL/1.0.2k mod_bwlimited/1.4 mod_wsgi/4.5.7 Python/2.7 configured -- resuming normal operations
Here is my VirtualHost configuration:
WSGIDaemonProcess brunamaiahair.com.br socket-user=#1004 python-path=/home/bmhair/public_html/django/framework:/home/bmhair/public_html/django/denv/lib/python2.7/site-packages
WSGIProcessGroup brunamaiahair.com.br
WSGIScriptAlias / /home/bmhair/public_html/django/framework/framework/wsgi.py
See socket-user option in:
http://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html
Recent CPanel installations seem to use PrivilegesMode set to SECURE so you will need to declare who should own the socket. It should be the user/uid Apache changes to when handling requests for you, rather than the default of the Apache user.
If for example the user which CPanel is setup to run your request as under Apache is bmhair, you need to add to the WSGIDaemonProcess directive in the Apache configuration the option:
socket-user=bmhair
After a restart of Apache, check in the directory where the socket file is placed, eg., /var/run/apache2 and check that socket file is owned by user bmhair.
Note that this will require that the directory /var/run/apache2 provides access to other users, ie., not just root or the user Apache runs your code as. If that is not the case, then use WSGISocketPrefix to move the socket file to another directory which is accessible to the user bmhair. Generally you should not need to even override WSGISocketPrefix as the default location used is fine. If you had set it explicitly for some reason, and didn't allow the default to be used, that could also be part of the problem.
The path /var/run/apache2 bmhair do not have access to that folder.Only root and approved users have.
So we need to show apache a path for wsgi socket.
If it is VPS:
WSGISocketPrefix /var/run/wsgi
If you are in a shared hosting:
WSGISocketPrefix ../../var/run/wsgi
Or
WSGISocketPrefix /home/bmhair/var/run/wsgi
As I can see you are in bmhair user so for you 2nd one will work.
I am using Easy apache 4, mod_wsgi, and Python 3.5. When I called a Django project in the server I got the following error:
(13)Permission denied: mod_wsgi (pid=24223): Unable to connect to WSGI daemon
process 'user123' on '/var/run/wsgi.8442.6.7.sock' as user with uid=3708.
Your Apache installation is likely set up to run with SECURE privileges mode. This means that the Apache child worker process is forked and privileges dropped before handling the request, which in this case is simply trying to proxy the request through to the mod_wsgi daemon process. The consequence of this is that it cannot connect to the socket for the daemon process, as it was setup with ownership to match the original Apache child worker process before privileges were dropped.
This is evident because the error message has uid in the range of a normal user and not the special apache or nobody user.
To fix it, you need to modify the WSGIDaemonProcess directive configuration and add the option:
socket-user=#3708
or:
socket-user=username
where username is replaced with the actual name of the user with uid of 3708.
The addition of this option seems to be required due to recent changes in CPanel configurations for Apache.
Sometime socket-user setting does not work.
This may occur because of WSGISocketPrefix path not found
If it is VPS:
WSGISocketPrefix /var/run/wsgi
If you are in a shared hosting:
WSGISocketPrefix ../../var/run/wsgi
Thank You