0

I have two VMs, the first one (vm-1) is running nginx as reverse proxy with the following configuration:

server {
  listen 80;
  server_name example.com;
  return 301 https://example.com$request_uri;
}
server {
  server_name example.com;
  location /app1 {
    proxy_pass http://ip-vm-2:8080;
  }
  location /app2 {
    proxy_pass http://ip-vm-2:80;
  }
  listen 443 ssl;
  ssl_certificate ....
}

For the second vm (vm-2), I have app1 (a standalone jar) on port 8080 which is working correctly and I can access it from https://example.com/app1.

For app2, I have installed nginx and copied a website to /var/www/html, altough I can access it from http://ip-vm-2, I does not work from https://example.com/app2, which is what I want.

I don't know exactly what the problem is with the configuration in the reverse proxy.

5
  • 1
    Doesn't the return statement of the first server block redirect to itself? – Tommiie Jan 29 '19 at 13:43
  • @Tommiie this statement will redirect to https any traffic coming from http – J. Bend Jan 29 '19 at 13:53
  • Ah, right! I didn't read the 'https' part. – Tommiie Jan 29 '19 at 13:54
  • Please describe does not work in more detail. Do you get wrong content? Do you get an error? If so, what's the error message? – Gerald Schneider Jan 29 '19 at 14:16
  • I get a 404 response – J. Bend Jan 29 '19 at 14:23
0

I haven't tried with VMs, but this seems logical.

VM1 nginx configuration server { listen 80; server_name example.com; return 301 https://example.com$request_uri; } server { server_name example.com; location /app1 { proxy_pass http://ip-vm-2:8080; } location /app2 { proxy_pass http://ip-vm-2; } listen 443 ssl; ssl_certificate .... }

VM2 nginx configuration

server { listen 80; server_name ip-vm-2; location / { root /var/www/html; try_files $uri $uri/ /index.html ; } }

Let me know if it works.

2
  • It works! The only change was removing the :80 in the reverse proxy? – J. Bend Jan 29 '19 at 14:29
  • If you have VM2 configured to listen to /path over 80, then you need to access it through /path over http. Good! – r_D Jan 29 '19 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.