django admin url not found (404) - django

I am a django beginner.
I receive the following message in /var/log/apache2/error.log (apache is set to debug level)
[Thu Aug 30 16:15:11 2012] [info] mod_wsgi (pid=5616): Initializing Python.
[Thu Aug 30 16:15:11 2012] [info] mod_wsgi (pid=5616): Attach interpreter ''.
[Thu Aug 30 16:15:15 2012] [error] [client 172.24.113.130] File does not exist: /var/www/netvistra3
[Thu Aug 30 16:15:19 2012] [error] [client 172.24.113.130] File does not exist: /var/www/netvistra3
My wsgi file is located in /usr/local/django/netvistra3/apache/netvistra3.wsgi
The admin site only seems to work with django's embedded webserver.
Snippet from apache2 virtual directory site:
Alias /static/admin /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin
WSGIDaemonProcess netvistra3 user=pbensel group=staff threads=5
WSGIScriptAlias /netvistra3 /usr/local/django/netvistra/apache/netvistra3.wsgi
<Directory /usr/local/django/netvistra3>
WSGIScriptReloading On
WSGIProcessGroup netvistra3
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
I greatly appreciate any help

Django has a bit of magic when running under it's own server that helps with this. When deploying on Apache, etc you are you're responsible for setting up Apache, or whichever media server you're using, to serve the admin files. The Django docs are pretty good on the topic. Please see the following link to the Django docs.
It's a pretty common problem. So, don't feel bad. Just Google if you need any more specific help for "deploy django admin"
Btw, I use the "collectstatic" approach for my projects and server them from an s3 bucket. It works great and seems to be a pretty common practice. At least with Django 1.3.

As David said, you have to take the right steps to set up static files. You have:
Alias /static/admin /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin
but are missing corresponding:
<Directory /usr/lib/python2.7/dist-packages/django/contrib/admin/static>
Order allow, deny
Allow from all
</Directory>
Don't have that and you will find static files fail with forbidden error.
I would though also check whether you have set up settings properly to say under what URL the static media is available.
If the static files are not served properly, you will be missing all the stlying for the admin pages, which could be considered as not working properly.
Also look into collectstatic as suggested as not always a good idea to refer to static media out of the Python installation like you are doing.

Related

Django website very slow using Apache and mod_wsgi

so today I tried to host a website using django on a Ubuntu vServer using Apache and mod_wsgi.
First I tested it with a blank django project, and everything worked perfectly, but as soon as I put my django project on the server and set Apache up to run with that, the performance of the server dropped a lot. When accessing the website using apache, the response time is about 10 seconds per page, in contrast do about 100ms when using the django dev server.
I should mentiona that the server has 8GB of ram and a quad-code cpu. When running htop not even 1% CPU usage and about 50MB of ram are used. When im accessing the website, the cpu usage gets really high for a second, just before the website is loaded and then goes back to <1%
Does any body have any tips on what could be the cause of that? I've read that there may be problems with the some mpm workers, but i didnt really find the files i would need to adjust on my server.
The apache server config looks like this(paths changed):
<VirtualHost *:80>
. . .
Alias /static /home/sammy/myproject/static
<Directory /home/sammy/myproject/static>
Require all granted
</Directory>
<Directory /home/sammy/myproject/myproject>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess myproject python-home=/home/sammy/myproject/myprojectenv python-path=/home/sammy/myproject
WSGIProcessGroup myproject
WSGIScriptAlias / /home/sammy/myproject/myproject/wsgi.py
In my error.log file, i also get a lot of these errors:
Mon Nov 23 11:20:12.551962 2020] [wsgi:alert] [pid 26252:tid 140403038272448] (11)Resource temporarily unavailable: mod_wsgi (pid=26252): Couldn't create worker thread 2 in daemon process 'myproject'.
and
Exception ignored in: <bound method BaseEventLoop.del of <_UnixSelectorEventLoop running=False closed=False debug=False>>
Traceback (most recent call last):
File "/usr/lib/python3.6/asyncio/base_events.py", line 526, in del
NameError: name 'ResourceWarning' is not defined
Also, here is the "apachectl status" when idling: https://pastebin.com/D40pRNSY

How to install a server at home with django&postgre

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/).

Unable to connect to WSGI daemon process mod_wsgi in Centos7 with Cpanel/WHM

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.

Apache on Amazon EC2 Not Connecting To My Django Site

I have an Amazon EC2 instance running Ubuntu and I'm trying to get it to display my Django site. The dev server works (i.e. if I run the dev server on the instance and go to http://ec2-XX-XXX-XX-XX.us-west-2.compute.amazonaws.com/:8000, my site works fine) but I can't get it to run properly via apache.
I've read about a thousand tutorials and so far none have been successful. Here is my most recent attempt - my Django site is stored in /home/ubuntu/Amazon/repo/my_site/.
I've tried creating a virtual host file in /etc/apache2/sites-available/ec2.conf with the following:
<VirtualHost *:80>
ServerName ec2-XX-XXX-XX-XX.us-west-2.compute.amazonaws.com
ServerAlias *.compute.amazonaws.com
WSGIScriptAlias / /home/ubuntu/Amazon/repo/my_site/my_site/apache/apache.wsgi
<Directory />
Require all granted
</Directory>
</VirtualHost>
After that, I ran sudo a2ensite ec2 to add the conf file to sites-enabled but going to ec2-XX-XXX-XX-XX.us-west-2.compute.amazonaws.com in my browser still returns to the default page.
Any guidance would be great, I'm sure I'm missing several steps, but I'm completely lost at the moment. There are a lot of things I don't understand at the moment such as:
Do I need a /var/www/html/ directory somewhere? Or does Django handle that?
Do I need to use virtual hosts at all? Or is that only for subdomains?
Do I need to register a domain name prior to getting it working? All the examples I see use something like "example.com" where I have "ec2-XX-XXX-XX-XX.us-west-2.compute.amazonaws.com". I have the domain name registered but I haven't pointed it at my amazon instance yet - I was hoping to first get it working.
Edit: Apache error.log output:
[Tue Jul 08 16:07:47.983174 2014] [mpm_event:notice] [pid 5054:tid 140062636054400] AH00491: caught SIGTERM, shutting down
[Tue Jul 08 16:07:49.046666 2014] [mpm_event:notice] [pid 5211:tid 139882510350208] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations
[Tue Jul 08 16:07:49.046735 2014] [core:notice] [pid 5211:tid 139882510350208] AH00094: Command line: '/usr/sbin/apache2'

Running a C++ cgi program on apache?

I'm experimenting with compiled cgi's on a test server, but I can't seem to get them to run.
I added this to apache;
<Directory /var/www/app>
AllowOverride All
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
Even tried this:
<Files "/var/www/app/monkey.cgi">
Options +ExecCGI
</Files>
But every time it runs, apache tells me
Fri Aug 17 01:55:07 2012] [error] [client 192.168.1.66] Options ExecCGI is off in this directory: /var/www/app/monkey.cgi
I've done this before, and it's worked, but it's been awhile. Off the top of your head, can you tell me if I'm making any glaring mistakes?
Thanks.
Is there any .htaccess file in your directory? And check the whole conf to see if you're not messing it up somewhere.
Additional info: Apache does add some defaults concerning CGI scripts on some version or distributors add those defaults.
Have you tried reloading your Apache configuration? The below command line works in general:
sudo service apache2 force-reload
Otherwise might have to refer to other command line commands as based on your Linux distro as seen in link below which covers it more specifically:
http://www.microhowto.info/howto/cause_a_system_service_to_reload_its_configuration.html