在我使用location声明静态文件后,Nginx无法加载它们



我已经配置了Nginx,如您所见:

server {
    listen 443 ssl;
    ssl on;
    ssl_certificate /etc/nginx/ssl/bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/privateKey.key;
    location /webmin/ {
            proxy_pass http://127.0.0.1:10000;
    }
server {
    listen 80;
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/privateKey.key;
    server_name localjob.it;
    access_log off;
    location / {
          alias /webapps/sitoweb/;
    }

现在,如果我在mysite.com上,页面会加载CSS,但如果我添加:

    location ~* .(css|js|gif|jpe?g|png)$ {
          expires 168h;
          add_header Pragma public;
          add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }

现在,如果我在mysite.com上,页面无法加载CSS。我不明白原因!!

Nginx location是独占的,因此您的别名在slide根位置不适用于另一个location。此外,这有点误用,只需在server块中使用root指令即可。

server {
    listen 80;
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/privateKey.key;
    server_name localjob.it;
    access_log off;
    root /webapps/sitoweb;
    location ~* .(css|js|gif|jpe?g|png)$ {
          expires 168h;
          add_header Pragma public;
          add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    }
}

相关内容

  • 没有找到相关文章

最新更新