「Django筆記」修訂間的差異

增加 1,307 位元組 、 2022年6月3日 (五) 07:11
無編輯摘要
行 49: 行 49:


如果不是 John,就回傳 Http404()。
如果不是 John,就回傳 Http404()。
==設定Gunicorn==
    /etc/systemd/system/gunicorn.service                                                             
<pre>
Group=www-data
WorkingDirectory=/root/lianlok               
ExecStart=/usr/local/bin/gunicorn(或其他絕對路徑) --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock lianlok.wsgi:application
[Install]
WantedBy=multi-user.target
</pre>
==設定 nginx==
site-available 裏面的 test 設定檔為:
<pre>
server {
listen 80;
server_name kianting.ddns.net 127.0.0.1;
# https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production
# location /static/ { # STATIC_URL
#    alias /home/www/example.com/static/; # STATIC_ROOT
#                  }
    access_log /root/log/lianlok-access.log;
    error_log /root/log/lianlok-error.log;
    location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://127.0.0.1:8080;
        }
}
</pre>


==參考==
==參考==
* https://docs.djangoproject.com
* https://docs.djangoproject.com
* http://stackflow.com
* https://stackoverflow.com/questions/58024196/nginx-proxy-pass-gunicorn-can-t-be-reached
* https://chentsungyu.github.io/2020/07/19/Python/Django/%5BDjango%5D%20%E5%9C%A8Ubuntu%E4%B8%AD%E9%81%8B%E7%94%A8Nginx%E3%80%81Gunicorn%20%E6%9E%B6%E8%A8%AD%20Django%20API%20Server