1

I'm trying to configure nginx to serve two independent Vue.js web-apps (let's call them app1 and app2). Applications are served as static html files on separate servers:

server {
    server_name app1;
    listen 9101;

    location / {
    root html\app1;
    index index.html;
    }
}
server {
    server_name app2;
    listen 9102;

    location / {
    root html\app2;
    index index.html;
    }
}

I configured the main server to act as reverse proxy:

server {
    server_name apps;
    listen 80;

    location ^~ /app1 {
        proxy_pass http://localhost:9101/;
    }

    location ^~ /app2 {
        proxy_pass http://localhost:9102/;
    }
}

The desired effect would be to run apps based on provided url (e.g. run app 1 when going to localhost/app1).

The problem is that html files locate their resources through root prefixed relative paths. For example both app1/index.html and app2/index.html will try to fetch their js files using the /js/app-*.js.

How can I configure nginx to recognize which app the request is coming from and route it to valid server?

EDIT: To clarify, what I'm trying to achieve:

  • Client goes to http://example.com/app1
  • html/app1/index.html gets loaded.
  • Every request sent from html page to / gets routed to app1/ (so link to /js/script.js in html code gets actually fetched from /app1/js/script.js)
  • Same goes for app2.

Apps are for internal use only (server is accessible through intranet).

rufus1530
  • 111
  • 2
  • First you have to figure out how to tell, based on the path, which server to pass the request to. There's nothing in the question that might help any of us do this, so you should provide the additional details. – Michael Hampton Nov 19 '18 at 15:58
  • either devs need to change the code for includes/baseurl/references or you can separate them via DNS/hostname and not directory - `app1.example.com` and `app2.example.com`. – ivanivan Nov 19 '18 at 16:00
  • Added more details on what I'm trying to achieve. @ivanivan, server is accessible through intranet. Can I set up subdomains on the server-level, or will I need assistance from someone managing my company's intranet? – rufus1530 Nov 19 '18 at 16:17
  • also read this it is short. https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ – titus Nov 19 '18 at 18:28

0 Answers0