【问题标题】:How to implement Nginx 'Service Unavailable' with SSL?如何使用 SSL 实现 Nginx 的“服务不可用”?
【发布时间】:2017-07-11 09:23:30
【问题描述】:

最近我将我的 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 ###
}

【问题讨论】:

    标签: django ssl nginx


    【解决方案1】:

    您的root 语句不在范围内。你应该把它移到location / 块之外。

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

    请参阅this document 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2015-03-20
      • 2019-07-06
      • 2019-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-28
      • 1970-01-01
      • 2019-05-31
      相关资源
      最近更新 更多