Config nginx for static

I can access this url http:// 127.0.0.1:8089/ static/css/style.css
But cannot access with Nginx proxy

server {
    listen       80;
    server_name  mydomain.com
    access_log off;
    return 301 https://$host$request_uri;
}

server {
    listen       443 ssl;
    server_name  mydomain.com
    ssl_certificate     /etc/nginx/ssl/mydomain.crt;
    ssl_certificate_key /etc/nginx/ssl/mydomain.key;
    access_log off;
    location / {
        proxy_pass http://127.0.0.1:8089;
    }
    location ~* \.(?:css|js)$ {
        expires 1h;
        access_log off;
        add_header Cache-Control "public";
    }
    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
        expires 4h;
        access_log off;
        add_header Cache-Control "public";
    }
}

Please help !

Sorry, I am not 100% clear what you are trying to achieve. To get this straight, you are trying to serve static content from Sanic? Or, trying to serve static content from NGINX and just proxy everything else to Sanic?

Are you trying to achieve something similar to this?

server {

    ...

    location /static {
        alias /usr/src/app/project/static;
    }
 
    location / {
        proxy_pass http://127.0.0.1:8089;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
1 Like

Thank you. I have just remove location ~* and it’s worked ^^