私はフォローしましたこれガイドとこれguniconrn と apache を使用して Django をデプロイします。
でも、よく分からないこれガイドにはこう書かれています:
(上記に加えて、静的ファイルとメディア ファイルのエイリアスとを指定する必要があります。)
いずれにせよ、これらはすべて私の設定です。私のDjangoアプリは/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
ソケット:
[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 -
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
Apacheを再起動した後、403が表示されますhttp://127.0.0.1/またはhttp://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
何か案は?
私はUbuntu 17.04を使用しています
編集:
いくつかの Python プロセスが実行されているのがわかりますが、それが正しいかどうかはわかりません。
$ 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
答え1
これは古い質問であることは承知しており、OP が問題を解決した可能性もありますが、私が見る限り、ポート 8000 で Gunicorn を起動し、同じポートを listen するように Apache に指示しています。2 つのアプリケーションが同じポートを listen しているため、競合が発生している可能性があります。プロセスの出力から判断すると、gunicorn はすでに実行されています。ApacheListen 8000
構成ファイルから削除し、Apache を再起動するだけで十分です。これで問題は解決するはずです。