Nuxt.js: Use nginx do reverse proxy, js file path all can't find it, how to solve?

Created on 24 Jul 2017  Â·  12Comments  Â·  Source: nuxt/nuxt.js

Use nginx do reverse proxy, js file path all can't find it, how to solve?

image

question

Most helpful comment


        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

Can you disable this line? (Nuxt already sets appreciate cache headers)

All 12 comments

Hi. Would you please share virtual host config used for reverse proxy? Nuxt is working for us behind multiply reverse proxies ...

nginx config

upstream shudong {
       server 127.0.0.1:3000;
}

server{
        listen 80;
        #listen [::]:80;
        server_name shudong.wang;
        index index.html index.htm index.php default.html default.htm default.php;
        #root  /home/wwwroot/shudong.wang/.nuxt/;

        #include other.conf;
        #error_page   404   /404.html;
        #include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location / {
                proxy_set_header X-Real-Ip $remote_addr;
                proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Nginx-Proxy true;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
                proxy_pass http://shudong;
                proxy_redirect off;
                #try_files $uri $uri/ /index.html;
                #if (-f $request_filename/index.html){
                #        rewrite (.*) $1/index.html break;
                #}
                #if (-f $request_filename/index.php){
                #        rewrite (.*) $1/index.php;
                #}
                #if (!-f $request_filename){
                #rewrite (.*) /index.php;
                #}
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/shudong.wang.log;
    }

root /home/wwwroot/shudong.wang/.nuxt/;

Why this line is commented out? If using nuxt generate you have to serve /home/wwwroot/shudong.wang/dist directory instead.

@pi0 I use the NPM run build;NPM start;Launched the port 3000, intends to use the reverse proxy, nginx configuration above, use access http://shudong.wang:3000 or 120.27.245.209:3000 no problem, following a visit to the agent address in file path not found, expect to have a correct reverse proxy configuration

Don't use nuxt generate, use npm build; npm start or pm2 ./build/main.js ï¼› then nginx proxy There is a problem


        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

Can you disable this line? (Nuxt already sets appreciate cache headers)

Now I try it on

Is studied for a week, didn't I think of this problem, now problem solved, thank you very much!!!!!!

Your welcome. Problem is that nginx matches closest location and in this case it skipped proxy pass in location /.

@wsdo any suggestion i have the same issue https://github.com/nuxt/nuxtjs.org/issues/42

@pi0 you saved me.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

o-alexandrov picture o-alexandrov  Â·  3Comments

mikekidder picture mikekidder  Â·  3Comments

maicong picture maicong  Â·  3Comments

gary149 picture gary149  Â·  3Comments

bimohxh picture bimohxh  Â·  3Comments