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 /前端階段/dist/東西/

我在前端使用 Angular 9

請指教

答案1

您有一個文檔根集,因此它使用該路徑 root /home/ubuntu/mysite/dist;

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

相關內容