Nginx 无法重定向 js、css、jpeg 文件

Nginx 无法重定向 js、css、jpeg 文件

请通过以下 nginx.conf 文件查找:

server {
    listen   81;

    server_name www.mysite.com;
    root /home/ubuntu/mysite/dist;
    index index.php index.html index.htm;

    charset utf-8;

        # Remove trailing slash to please Laravel routing system.
        #if (!-d $request_filename) {
        #rewrite  ^/(.+)/$ /$1 permanent;
        #}

    error_log  /var/log/nginx/myapp-error.log warn;
location / {
    try_files $uri /index.html;
   }
 location /temp {
        alias /var/www/frontend-stage/dist/something/;
        # basically $uri and /$uri resembles the base path which is / and the path on which we're currently, so for an example if i
        # want to host another website on /temp/foo the the $uri /temp/$uri
         try_files $uri $uri/ /temp/index.html;

   }
...

当我从 chrome 打开 www.mysite.com/temp/something 时,它会正确获取 index.html,但其余所有 js、css、jpeg、png 等都从 /home/ubuntu/mysite/dist 获取,而不是从 /var/www/frontend-stage/dist/something/ 获取

我在前端使用 Angular 9

请指教

答案1

您有一个文档根目录集,因此它使用该路径根目录 /home/ubuntu/mysite/dist;

看这里: https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/

相关内容