簡體   English   中英

腳本標簽中的Javascript在Nginx代理傳遞之后不執行

[英]Javascript in script tag doesn't execute behind nginx proxy pass

我有一個在Nuginx proxy_pass后面運行的Nuxtjs構建的網站。

假設Nuxtjs站點位於http://10.001.002.003/ ,主要站點是http://example.com 這是example.com的Nginx配置

        location /main-page/ {
            proxy_pass http://10.001.002.003/; #this is the Nuxt site
        } 

         location /api/ {
            rewrite /api/(.*) /$1  break;
            proxy_pass https://api.example.com/;
        }

        location / {
            root /home/www/html/example/dist;
            try_files $uri $uri/ /index.html;
            #index index.html;
        }

我在http://10.001.002.003/_nuxt/script1.js有一個腳本,該腳本又可以從http://example.com/main-page/_nuxt/script1.js訪問

這是問題所在,如果我瀏覽到http://example.com/main-page ,則腳本不會執行。 但是,如果我瀏覽到http://10.001.002.003 ,它將起作用。

這是HTML

<head>
<link rel="preload" href="http://example.com/main-page/_nuxt/script1.js" as="script">
</head>

<body>
<script src="http://example.com/main-page/_nuxt/script1.js" defer></script>
</body>

(1):傳遞請求標頭:

location /main-page/ {
    proxy_pass http://10.001.002.003/; #this is the Nuxt site
    proxy_pass_request_headers on;
}

(2):在nuxt.config.js中將基礎添加到路由器: https ://nuxtjs.org/api/configuration-router#base

router: {
    base: '/main-page/',
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM