9

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?

2 Answers 2

8

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

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

location / {
  return 200 'http_pong';

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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