0

I'm trying to setup up a really simple thing:

use Nginx to listen to port 8080 and forward everything to internal host with port 80. This is my config so far:

server {
    listen 8080;
    server_name publichost;

    location / {
        proxy_set_header   Host $http_host;
        proxy_pass http://app1;
    }
}
server {
    listen 80;
    server_name publichost;

    location / {
        proxy_set_header   Host $http_host;
        proxy_pass http://app2;
    }
}

So far so good. Now when I open http://publichost:8080 it works and the browser shows the index.html site.

But now, every resource link in this index.html try to load files from app2

<link rel="stylesheet" type="text/css" href="http://publichost/static/styles.css">

this totally makes sense, since the proxy forwards every requests with port 8080 to my app1 and uses internal port 80, and every request with port 80 goes to app2.

My question is: How can I configure nginx proxy, so that it just works? I want to be able to have another webapplication that is reachable via default port 80.

Notice Maybe it is important to notice that the application is magento2 which stores its baseurl in database. So I have to set it appropriately once and should not change it. Magento then generates the urls to resources like css, javascript and images with that base url.

artgrohe
  • 151
  • 1
  • 9
  • Use [`proxy_redirect`](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect), e.g. `proxy_redirect http://localhost:8080 http://app2;` and don't forget your trailing slashes in `proxy_pass` (I think you need them in your config) – Lenniey Mar 29 '19 at 12:43
  • `proxy_redirect` only rewrites response headers, it does not touch the response body. The proper fix is to fix the misbehaving web application. – Michael Hampton Mar 29 '19 at 12:59
  • You can use `sub_filter` to modify the response body, but it's not a scalable solution. – Richard Smith Mar 29 '19 at 14:03

1 Answers1

0

That's likely app dependent.

Sometimes app's respond to a header (IE 'x-script-name' for frameworks like Django) or have a custom mechanism for re-writing URL's (IE Plone's VirtualHostMonster). Sometimes they just have a setting in the app.

Joel Kleier
  • 131
  • 1