403 verboten für Django + Gunicorn + Systemd + Apache?

403 verboten für Django + Gunicorn + Systemd + Apache?

Ich bin gefolgtDasführen undDasum mein Django mit Guniconrn und Apache bereitzustellen.

Aber ich verstehe nicht ganz, wasDasin der Anleitung steht:

(Zusätzlich zu den oben genannten Angaben müssen Sie noch Alias ​​und für die statischen und Mediendateien angeben.)

Aber das sind jedenfalls alle meine Konfigurationen. Meine Django-App ist bei/var/www/html/django-project/helloapp

/etc/systemd/system/gunicorn.service:

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
PIDFile=/run/gunicorn/pid
User=lau
Group=lau
RuntimeDirectory=gunicorn
WorkingDirectory=/var/www/html/django-project/helloapp
ExecStart=/usr/bin/gunicorn --pid /run/gunicorn/pid   \
          --bind unix:/run/gunicorn/socket helloapp.wsgi
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

/etc/systemd/system/gunicorn.socket:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn/socket

[Install]
WantedBy=sockets.target

/etc/tmpfiles.d/gunicorn.conf:

d /run/gunicorn 0755 lau www-data -

/etc/apache2/apache2.conf:

<Directory /var/www/html/django-project/helloapp>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Require all granted
</Directory>

/etc/apache2/sites-available/000-default.conf:

<VirtualHost *:80>
ProxyPass /static/ !
ProxyPass /media/ !
ProxyPass / http://localhost:8000/

</VirtualHost>

/etc/apache2/ports.conf:

Listen 80
Listen 8000

Nach dem Neustart meines Apache erhalte ich 403 beihttp://127.0.0.1/oderhttp://127.0.0.1:8000

Forbidden

You don't have permission to access / on this server.
Apache/2.4.25 (Ubuntu) Server at localhost Port 8000

Irgendwelche Ideen?

Ich verwende Ubuntu 17.04

BEARBEITEN:

Ich sehe einige laufende Python-Prozesse, bin mir aber nicht sicher, ob das richtig ist oder nicht:

$ ps -wef | grep python
root      2418     1  0 06:16 ?        00:00:00 /usr/bin/python3 /usr/share/apt-xapian-index/update-apt-xapian-index-dbus
lau      25488 28678  0 23:49 pts/2    00:00:00 grep --color=auto python
lau      30605     1  0 18:30 ?        00:00:02 /var/www/html/django-project/helloapp/env/bin/python /var/www/html/django-project/helloapp/env/bin/gunicorn --workers 3 --bind unix:/var/www/html/django-project/helloapp.sock helloapp.wsgi:application
lau      30609 30605  0 18:30 ?        00:00:00 /var/www/html/django-project/helloapp/env/bin/python /var/www/html/django-project/helloapp/env/bin/gunicorn --workers 3 --bind unix:/var/www/html/django-project/helloapp.sock helloapp.wsgi:application
lau      30610 30605  0 18:30 ?        00:00:00 /var/www/html/django-project/helloapp/env/bin/python /var/www/html/django-project/helloapp/env/bin/gunicorn --workers 3 --bind unix:/var/www/html/django-project/helloapp.sock helloapp.wsgi:application
lau      30612 30605  0 18:30 ?        00:00:00 /var/www/html/django-project/helloapp/env/bin/python /var/www/html/django-project/helloapp/env/bin/gunicorn --workers 3 --bind unix:/var/www/html/django-project/helloapp.sock helloapp.wsgi:application

Antwort1

Ich weiß, dass dies eine alte Frage ist, und OP hat das Problem möglicherweise gelöst, aber soweit ich sehen kann, haben Sie Gunicorn auf Port 8000 gestartet und Apache angewiesen, auf demselben Port zu lauschen. Da zwei Anwendungen auf demselben Port lauschen, verursacht das wahrscheinlich den Konflikt. Gemessen an der Ausgabe Ihrer Prozesse läuft Gunicorn bereits. Es reicht aus, es Listen 8000aus der Apache-Konfigurationsdatei zu entfernen und Apache erneut zu starten. Dies sollte das Problem lösen.

verwandte Informationen