0

I want nginx first redirect http to https, then check for static files in www root dir, if none, pass request to proxy. However, after http->https redirect requests are immediately passed to proxy.

On same server (127.0.0.1 as seen from nginx) port 8000 I have simple flask app that return a string on request to "/":

...
@app.route("/")
def root():
    return "Works!"
...

It works ok (checked in browser).

Nginx conf is

server {
    listen 80;
    listen [::]:80;
    server_name lpch $DOMAIN www.$DOMAIN;
    return 301 https://$host$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name lpch $DOMAIN www.$DOMAIN;
    ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;

    root /var/www/$DOMAIN/html;
    index index.html index.htm;

    location / {
      try_files $uri index.html @proxy_to_app;
    }

    location @proxy_to_app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://127.0.0.1:8000;
    }
}

What am I doing wrong?

0 Answers0