Tyl*_*ell 5 django ssl https nginx gunicorn
我正在使用Nginx和gunicorn服务我的Django项目。我目前有它适用于ssl(https),但不太了解设置文件和nginx的正确设置。有人可以看看我的设置,并告诉我是否有任何公然看起来错误或可怕地执行的事情?
我的Nginx文件,请注意,有些行已被注释掉。当我取消评论时,该站点停止工作。编辑:当我同时取消所有注释/
server {
server_name example.com;
listen 443 ssl;
ssl on;
ssl_certificate /etc/ssl/mycrt.crt;
ssl_certificate_key /etc/ssl/mykey.key;
location = /favicon.ico {access_log off; log_not_found off;}
location /static/ {
gzip on;
gzip_types text/css;
alias /home/project/static/;
}
location / {
include proxy_params;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
# proxy_set_header Host $http_host;
# proxy_redirect off;
proxy_pass http://unix:/home/project/myproject/project.sock;
}
}
server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}
Run Code Online (Sandbox Code Playgroud)
我的独角兽文件
[Unit]
Description=gunicorn daemon
After= network.target
[Service]
User=tyler
Group=www-data
Environment="Production=production"
WorkingDirectory=/home/project/myproject
ExecStart=/home/project/projectenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/projecty/myproject_a$
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
最后是dajngo设置
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
Run Code Online (Sandbox Code Playgroud)
此设置有任何问题吗?我对Nginx设置感到非常困惑,为了让https开始工作,我不得不对其进行注释。另外,我知道Django在使用SECURE_PROXY_SSL_HEADER =('HTTP_X_FORWARDED_PROTO','https')设置时非常谨慎。一切都好吗?
谢谢!
这个对我有用。我不确定这对你有用,但你可以尝试一下。
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/home/project/myproject/project.sock;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
809 次 |
最近记录: |