0

As a test, I enabled the nginx status page as per these articles

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;
}

I'm normally running a wordpress site, and redirecting any http request to an https request:

server {
   server_name _;
   listen 80;

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

I have several https server blocks, one for each dns which has it's own server cert.

Is there some way of combining the two server blocks above, so that normally an http request will redirect to https, but if the /status url is used, it will activate the nginx status page?

Jeremy
  • 44,950
  • 68
  • 206
  • 332

1 Answers1

0

You need do something like below

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;

}

So in case of /status no redirection will happen. In rest cases it will just do the https redirect

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
  • I'll try this. I always thought "location /" meant requests to the site root, but it sounds like you are implying it's basically a wildcard meaning any request. – Jeremy Nov 07 '17 at 22:40
  • Yes. That is why the `=` with `/status`. So `/status/xyz` still goes to `/` – Tarun Lalwani Nov 07 '17 at 22:41