Nginx url rewrites internal location

I have two applications running on ports 8080 and 5999. I want to use nginx to proxy for the two applications both /rssand /demo.

But the problem that I am facing is that css, javascript are not loading.

location /rss {
  rewrite ^/rss(.*) /$1 break;
  proxy_pass http://localhost:8080/;
  proxy_redirect off;
}

location /demo {
  rewrite ^/demo(.*)$ /$1 break;
  proxy_pass http://localhost:5999/;
  proxy_redirect off;
}

Can someone please help me fix this ...

+4
source share
1 answer

Firstly, I think the following is slightly ahead (avoiding double slashes in the proxy request):

location /rss/ {
  rewrite ^/rss/(.*) /$1 break;
  proxy_pass http://localhost:8080;
  proxy_redirect off;
}

location /demo/ {
  rewrite ^/demo/(.*)$ /$1 break;
  proxy_pass http://localhost:5999;
  proxy_redirect off;
}

Secondly, you need to make sure your CSS, etc. are correctly specified in your HTML.

If the CSS file was specified like this in HTML, before proxying:

http://localhost:8080/styles/application.css

- HTML, , ( ) :

http://notproxied.com/rss/styles/application.css
0

All Articles