P
P
Pavel2021-10-06 14:26:31
Nginx
Pavel, 2021-10-06 14:26:31

How to correctly direct nginx to 2 servers?

there are 2 nextcloud servers,
my config is for the first one

site.conf
server {

listen 80;

server_name my_domain.com.ua  www.my_domain.com.ua;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header X-Forwarded-Host $host:$server_port;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

location / {

proxy_pass http://192.168.1.7/;
client_max_body_size 0;
}

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/my_domain.com.ua/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/my_domain.com.ua/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


}
server {
    if ($host = www.my_domain.com.ua) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = my_domain.com.ua) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

server_name my_domain.com.ua  www.my_domain.com.ua;
    listen 80;
    return 404; # managed by Certbot
}


I do a similar config for the second server, but the nginx reboot says that it cannot work on two listeners on ports 80 or 443, if the ports are completely removed, then server_name is not enough for him, what if both servers need port 80 and 443?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2021-10-06
@mrusklon

Rewrite your spaghetti with weird conditions into normal independent blocks that have unique accepted domain names. Optional - expand the ports too.

D
Drno, 2021-10-06
@Drno

https://techexpert.tips/ru/nginx-ru/nginx-virtualh...
https://coderoad.ru/11693135/%D0%BD%D0%B5%D1%81%D0...
https:/ /kztarif.ru/kompjutery/nginx-neskolko-sajto...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question