8

I have a redirect to force https:

server {
    listen 80;

    server_name example.com;
    return 301 https://example.com$request_uri;
}

Works great, but I would like to be able to hit a single text file through http using the echo module:

server {
    listen 80;

    location /ping {
        echo "http_pong";
    }

    server_name example.com;
    return 301 https://example.com$request_uri;
}

Unfortunately I can never get to /ping as I get the 301 redirect instead. How can I prevent the global redirect from applying to that single location?

7

Try putting redirect under location /, like this:

server {
    listen 80;
    server_name example.com;

    location /ping {
        echo "http_pong";
    }

    location / {
        return 301 https://example.com$request_uri; 
    }
}
| improve this answer | |
0

Be aware - "echo" is deprecated. Use "return"

location / {
  return 200 'http_pong';

}

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.