Nginx 404 issue when serving static files of a sub-directory -
i have 404 error when trying access css , js files of sub static directory. tried use =, or ~ still not work.
mydomain/sub/index.html is served.
mydomain/sub/css/style.css is not served.
here nginx configuration file :
server {   listen 80;   server_name www.example.com example.com;    return 301 https://www.example.com$request_uri; }  server {   # global   listen 443 ssl http2;   server_name www.example.com example.com;   charset utf-8;    # logs   ...    # ssl   ...    # ocsp stapling   ...    # hsts   ....    # robots   location /robots.txt {     return 200 "user-agent: *\nallow: /";   }    # sub   location /sub {     alias /www/sub;     index index.html;     try_files $uri $uri/ =404;   }    # page speed   include /etc/nginx/pagespeed.conf;    # set expiration policy   location ~* \.(?:ico|css|js|gif|jpe?g|png|woff)$ {     expires 7d;     add_header pragma public;     add_header cache-control "public";      proxy_pass http://example;   }    # location   location / {     if ($request_method = post) {       return 500;     }      proxy_pass http://mydomain;   }  } 
in case, sub directory should use sub location, wish you.
    location /company/default/static/ {         alias /data/pro/static_deployment/ ;          autoindex off;          location ~* \.(js|css|png|jpg|jpeg)$ {             expires 7d;          }     } 
Comments
Post a Comment