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

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .