【问题标题】:nginx status page configurationnginx状态页面配置
【发布时间】:2017-11-07 22:15:14
【问题描述】:

作为测试,我根据这些文章启用了 nginx 状态页面

server {
    listen 80;

    #listen on any host name
    server_name _;

    location /status {
        stub_status on;
        access_log off;
    }

    access_log  /var/log/nginx/$host-access.log;
    error_log   /var/log/nginx/monitor-error.log;
}

我通常运行一个 wordpress 网站,并将任何 http 请求重定向到 https 请求:

server {
   server_name _;
   listen 80;

   return 301 https://$host$request_uri;
}

我有几个 https 服务器块,每个 dns 都有一个,它有自己的服务器证书。

有没有什么办法可以把上面的两个server块结合起来,让正常的http请求重定向到https,但是如果使用/status url,会激活nginx状态页面?

【问题讨论】:

    标签: nginx nginx-status


    【解决方案1】:

    您需要执行以下操作

    server {
       server_name _;
       listen 80;
        location = /status {
            stub_status on;
            access_log off;
        }
    
        location / {
           return 301 https://$host$request_uri;
        } 
        access_log  /var/log/nginx/$host-access.log;
        error_log   /var/log/nginx/monitor-error.log;
    
    }
    

    所以在/status 的情况下不会发生重定向。在其他情况下,它只会执行 https 重定向

    【讨论】:

    • 我会试试这个。我一直认为“位置 /”表示对站点根目录的请求,但听起来你在暗示它基本上是一个通配符,表示任何请求。
    • 是的。这就是=/status 的原因。所以/status/xyz 还是去/
    猜你喜欢
    • 1970-01-01
    • 2014-11-23
    • 2019-02-12
    • 2012-11-28
    • 2017-07-30
    • 1970-01-01
    • 2015-04-22
    • 2013-12-27
    • 1970-01-01
    相关资源
    最近更新 更多