I want to serve specific file in http block, but me nginx configuration still redirects me to https. Here is my http block configuration:

server {
  listen       80;
  server_name  example.com;

  location /files/myfile.gz {
    alias /home/user/project/myfile.gz;
  }

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

1 Answers

1
mechsix Tsai On Best Solutions

It's because your second location rule will still match the first one /files/myfile.gz

If you'd like to serve the single file from Nginx, try this

server {
  listen       80;
  server_name  example.com;

  location =/files/myfile.gz {
    alias /home/user/project/myfile.gz;
  }

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