简体   繁体   中英

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

I have a site build by Nuxtjs running behind a nginx proxy_pass.

Let say the Nuxtjs site is at http://10.001.002.003/ , the main site is http://example.com . This is the nginx config for example.com

        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

Here's the problem, the script is not executed if I browse to http://example.com/main-page . However, it works if I browse to http://10.001.002.003 .

This is the 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:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM