Home > Software engineering >  Nginx listening on various ports
Nginx listening on various ports

Time:06-08

i have a small issue, i configured various server block with listen directive like below but i can access toto1.com on port 444 and toto2.com on port 443, but I would prefer if it's was not possible, the listen directive is not only for the server block?

server {
        listen 443 ssl http2;
        server_name toto1.com;
        include /etc/nginx/snippets/ssl.conf;

        location /
                        {
                proxy_read_timeout  900;
                        proxy_pass_header   Server;
                        proxy_set_header X-Real-IP  $remote_addr;
                        proxy_set_header X-Forwarded-For $remote_addr;
                        proxy_set_header Host $host;
                        proxy_pass         https://x.x.x.x;
                        }
                }
server {
        listen 444 ssl http2;
        server_name toto2.com;
        include /etc/nginx/snippets/ssl.conf;

        location /
                        {
                proxy_read_timeout  900;
                        proxy_pass_header   Server;
                        proxy_set_header X-Real-IP  $remote_addr;
                        proxy_set_header X-Forwarded-For $remote_addr;
                        proxy_set_header Host $host;
                        proxy_pass         https://x.x.x.x;
                        }
                }

thanks

CodePudding user response:

i found my answer here https://www.computerworld.com/article/2987967/why-your-nginx-server-is-responding-with-content-from-the-wrong-site.html

you need to create a conf server like that and place it at the begining

server {
include /etc/nginx/snippets/ssl.conf;
server_name titi.com;

listen 444;
listen 443;

return 404 ;

access_log  /var/log/nginx/default.access.log  main;
error_log /var/log/nginx/default.error.log;
}
  • Related