0

I recently uninstalled apache2 for Nginx I'm trying to listen on 88, 808 and 888 for my sites and redirect different subdomains for each (and another domain to another server). the problem is that Nginx is giving bad gateway for all proxied requests and timeout for the direct ip access.

proxy conf : --> otherdomain.fr = eror 502 bad gateway

# HTTP
server {
    # Listen on ipv4
    listen 80;
    #listen [::]:80;

    server_name  ~.*.otherdomain.fr;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass "http://192.168.1.17";
    }
}

server{
    listen 80;
    server_name nextcloud.domain.me;
    location / {
        proxy_set_header Host $host;
        proxy_pass "http://127.0.0.1:888";
        proxy_redirect off;
    }
}

server{
    listen 80;
    server_name domain.me;
    location / {
        proxy_set_header Host $host;
        proxy_pass "http://127.0.0.1:808";
        proxy_redirect off;
    }
}

ex for port 88: --> ip:88 = timeout

(obviously, it is enabled and the nginx user have access to the files)

server {
    # Listen on ipv4
    listen 88;
  
    location / {
        root /var/www/html/tests;
    }

}

I'm obviously doing something wrong but I cant find out what, if you could give me a hand it would be incredible. Thank you in advance!

EDIT :

netstat -tulpen | grep -E '8.?8'

tcp 0 0 127.0.0.1:10028 0.0.0.0:*
LISTEN 0 28186 1929/master tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 91603 8801/nginx: master tcp 0 0 127.0.0.1:12340
0.0.0.0:* LISTEN 0 25868 734/dovecot tcp 0 0 127.0.0.1:631 0.0.0.0:*
LISTEN 0 19881 497/cupsd tcp 0 0 0.0.0.0:88 0.0.0.0:* LISTEN 0 75033 8801/nginx: master tcp 0 0 0.0.0.0:888
0.0.0.0:* LISTEN 0 75032 8801/nginx: master tcp 0 0 0.0.0.0:443 0.0.0.0:*
LISTEN 0 75030 8801/nginx: master tcp 0
0 127.0.0.1:10025 0.0.0.0:* LISTEN 0
28182 1929/master udp6 0 0 :::32885
:::* 113 21172
482/avahi-daemon: r"""

7
  • What's the reason to differentiate the ports and then proxying them? What's the output of netstat -tulpen | grep -E '8.?8?'`` ? Do you have listen` directives for all of these ports?
    – digijay
    Commented Nov 3, 2021 at 19:49
  • 1./ I'm proxying and differentiate the ports because I use a different server for each one (808 is a cherrypy serv actually not running, otherdomain.fr is another machine (apache2), 888 is nextcloud with this instance of nginx (and php8.0) and I only use 88 for testing purposes so I don't use a subdomain for it) 2./ see EDIT 3./ yes I do Commented Nov 3, 2021 at 19:56
  • EDIT : I could remove the port for nextcloud and maybe port 88 Commented Nov 3, 2021 at 20:02
  • nginx requires either a location, an server name or an ip in the servername. else it will imho not serve the contents as it does not know whatever to do with it., moreover for what reason do you uae ~.*. in servername?
    – djdomi
    Commented Nov 4, 2021 at 17:42
  • What is the content of nginx error.log? Commented Nov 5, 2021 at 8:04

1 Answer 1

1

You don't need quotes around the destination URL of proxy_pass.

Main problem is the server_name ~.*.otherdomain.fr and the fact that you are using proxy_set_header Host $host.

In this case it seems your regular expression for server_name is invalid and it is taken as a string. That string appears then in $host variable.

You should try

server_name *.otherdomain.fr;

instead. If that doesn't work, use

proxy_set_header Host $http_host;

Which passes the HTTP Host header onward instead of contents of $host variable.

1
  • i was guessing correctly that regrx works but is conflict with the rest ;) thabks fir the clarification of my thoughts
    – djdomi
    Commented Nov 6, 2021 at 14:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .