gpt4 book ai didi

django - 如何用SSL实现Nginx 'Service Unavailable'?

转载 作者:太空宇宙 更新时间:2023-11-03 13:35:12 26 4
gpt4 key购买 nike

最近我将我的 Nginx/Gunicorn/Django 网站“mysite”转换为 SSL,并且 SSL 连接工作正常。对于该站点以前的非 SSL 版本,我在我的 Nginx 配置文件中创建了一些指令,这些指令在我进行维护时限制对该站点的访问并且它正常工作。但是,既然我已经将网站转换为 SSL,这些指令就不再有效了,我也不知道为什么。重写命令有问题吗?这是我的配置文件:

# /etc/nginx/sites-available/mysite.conf
server_tokens off;

upstream mysite_server {
server 127.0.0.1:8000 fail_timeout=0;
}

server {
server_name web01.mysite.com;
listen 80;
return 301 https://web01.mysite.com$request_uri;
}

server {
server_name web01.mysite.com;
listen 443 ssl;
ssl_certificate /srv/ssl/mysite.com/ssl-bundle.crt;
ssl_certificate_key /srv/ssl/mysite.com/mysite.com.key;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_dhparam /srv/ssl/mysite.com/dhparam.pem;
ssl_ciphers '<ciphers are here>';
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains;";
ssl_stapling on;
ssl_stapling_verify on;

client_max_body_size 4G;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

location / {
root /srv/http/mysite.com/repo;
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;

if (!-f $request_filename) {
proxy_pass http://mysite_server;
break;
}
}

location /static/ {
proxy_pass http://<file_server_ip_addr>;
}
location /media/ {
proxy_pass http://<file_server_ip_addr>;
}

### START 503 SERVICE UNAVAILABLE BLOCK ###
# Uncomment directives to invoke "503 Service Temporarily
# Unavailable" page

# Uncomment this conditional to limit access to all IP addresses
# if (-f $document_root/templates/503.html) {
# return 503;
# }
# error_page 503 @maintenance;
# location @maintenance {
# rewrite ^(.*)$ /templates/503.html break;
# }

# Uncomment this conditional to limit access to a specific IP.
# Look up the IP using a site like whatismyip.com.
# if ($remote_addr != "<specific_ip>") {
# return 503;
# }
# error_page 503 @maintenance;
# location @maintenance {
# rewrite ^(.*)$ /templates/503.html break;
# }
### END 503 SERVICE UNAVAILABLE BLOCK ###
}

最佳答案

您的 root 语句不在范围内。您可能应该将它移到 location/ block 之外。

root /srv/http/mysite.com/repo;
location / { ... }
...
if (-f $document_root/templates/503.html) { return 503; }
...

参见 this document了解更多。

关于django - 如何用SSL实现Nginx 'Service Unavailable'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42372667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com