[英]Javascript in script tag doesn't execute behind nginx proxy pass
I have a site build by Nuxtjs running behind a nginx proxy_pass. 我有一个在Nuginx proxy_pass后面运行的Nuxtjs构建的网站。
Let say the Nuxtjs site is at http://10.001.002.003/ , the main site is http://example.com . 假设Nuxtjs站点位于http://10.001.002.003/ ,主要站点是http://example.com 。 This is the nginx config for 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;
}
I have a script at http://10.001.002.003/_nuxt/script1.js which in turn can be accessed from http://example.com/main-page/_nuxt/script1.js 我在http://10.001.002.003/_nuxt/script1.js有一个脚本,该脚本又可以从http://example.com/main-page/_nuxt/script1.js访问
Here's the problem, the script is not executed if I browse to http://example.com/main-page . 这是问题所在,如果我浏览到http://example.com/main-page ,则脚本不会执行。 However, it works if I browse to http://10.001.002.003 .
但是,如果我浏览到http://10.001.002.003 ,它将起作用。
This is the html 这是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): Pass request headers: (1):传递请求标头:
location /main-page/ {
proxy_pass http://10.001.002.003/; #this is the Nuxt site
proxy_pass_request_headers on;
}
(2): Add base to router in nuxt.config.js: https://nuxtjs.org/api/configuration-router#base (2):在nuxt.config.js中将基础添加到路由器: https ://nuxtjs.org/api/configuration-router#base
router: {
base: '/main-page/',
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.