0

I have a weird issue happening in my Nginx server. I am using Nginx as a reverse proxy for multiple services running on my servers internally.

This is kind of what I was trying to accomplish:

app1.mydomain.com --- --- server 1: 10.0.0.2 \ 10.0.0.1 / |--- nginx reverse proxy server --- | / \ app2.mydomain.com --- --- server 2: 10.0.0.3 

So I added the first one for app1, added the DNS settings in my domain provider, and everything worked perfectly. I was pretty excited so I went for the second one and then everything broke. I ran nginx -t and everything tested fine. The Nginx server was still running without error but I lost the ability to view app1.mydomain.com

The configs are basically the same except for the server_name and the proxy_pass

file: /etc/nginx/sites-available/app1.mydomain.com

server { server_name app1.mydomain.com; location / { client_max_body_size 512M; proxy_pass http://10.0.0.2; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } 

file: /etc/nginx/sites-available/app2.mydomain.com

server { server_name app2.mydomain.com; location / { client_max_body_size 512M; proxy_pass http://10.0.0.3; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } 

The way I did this was adding each config in it's own file in sites-available and then doing sudo ln -s /etc/nginx/sites-available/app1.mydomain.com /etc/nginx/sites-enabled/

This worked perfectly for app1, but after doing that for app2 I lost access to app1 and app2 wouldn't appear.

In my router, I forwarded port 80 and 443 to the reverse proxy server 10.0.0.1 and those are the only rules on my router. On my domain name provider I have the correct A records pointed at the correct IP. I was able to verify everything works with app 1, but after doing a symlink for app 2 to go into sites-enabled and restart nginx I lose access to everything.

Any ideas as to what is going on? Thanks!

5
  • What does nginx -T show? Commented Sep 7, 2023 at 21:53
  • And what exact errors do you get? Commented Sep 7, 2023 at 21:54
  • The nginx configs shown here are incompete. Was this deliberate editing on the post or do you not have listen / certificate configuration? Commented Sep 8, 2023 at 8:26
  • nginx -t just shows nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful Commented Sep 8, 2023 at 14:48
  • You need to use nginx -T, note the capital T. That will display the full configuration. Commented Sep 8, 2023 at 15:12

1 Answer 1

0

@symcbean actually pointed out the answer. The configs I posted were incomplete. For app1 I used the exact config shown (which worked somehow) and then ran certbot which added the TLS config and listen variable to the config.

Then I added the config for app 2 (exactly as shown) and I didn't get any errors on the server but started getting the connection refused errors when I tried to access app 1 or app 2. After adding the listen config and restarting nginx everything started working.

Thanks!

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.