0

I have ubuntu 18.04 server with 2 dedicated ip addresses:

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 195.161.41.218  netmask 255.255.255.0  broadcast 195.161.41.255
        inet6 fe80::5054:ff:fef1:78  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:f1:00:78  txqueuelen 1000  (Ethernet)
        RX packets 111588  bytes 9971580 (9.9 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7619  bytes 11305323 (11.3 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 81.177.165.186  netmask 255.255.255.0  broadcast 81.177.165.255
        inet6 fe80::5054:ff:fe7e:bbc5  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:7e:bb:c5  txqueuelen 1000  (Ethernet)
        RX packets 101948  bytes 8734415 (8.7 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 204  bytes 34728 (34.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

And there I have 2 sites:

/var/www/site1
/var/www/site2

Site1 have ssl certificate installed. And the Site2 is currently created.

I have following vhost nginx configuration:

  map $sent_http_content_type $expires {    
        default                    off;     
        text/html                  epoch;     
        text/css                   max;     
        application/javascript     max;     
        ~image/                    max; 
    }

    server {
        listen 80 default_server;
        server_name default;
        location / {
            root /var/www/html;
            index index.html;
    }
    }

    server {
            listen 81.177.165.xxx:80;
            server_name *.site2.com;
            location / {
                    root /var/www/site2/public_html;
                    index index.html;
         }
    }

    server {
        listen 81.177.165.xxx:443 ssl;
        server_name *.site2.com;
        location / {
                    root /var/www/site2/public_html;
                    index index.html;
         }
    }


    server {
        listen 195.161.41.xxx:80;
        server_name site1;
        rewrite ^ https://$server_name$request_uri permanent;
    }

    server {
        listen 195.161.41.xxx:443 ssl;
        server_name site1;
        root /var/www/site1/web;
        access_log off;

        gzip on;
        gzip_disable "msie6";
            gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon; 
        gzip_comp_level 5;
        gzip_min_length 256;
        gzip_vary on;
        gzip_proxied any;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        ssl_certificate /etc/letsencrypt/live/site1/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/site1/privkey.pem; # managed by Certbot

        ssl_dhparam /etc/ssl/certs/dhparam.pem;

        location ~ \.php$ {     return 404; }  
        location /nginx_status {              
            stub_status on;               
            allow all;        
        }  
        location / {    
            try_files $uri @fallback; 
        }  
        location @fallback {    
            fastcgi_pass 127.0.0.1:9000;    
            include fastcgi_params;     
            fastcgi_param SCRIPT_FILENAME $document_root/app.php; 
            fastcgi_param HTTPS $https;
            proxy_set_header X-Forwarded-Proto https;     
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;     
            proxy_set_header Host $http_host;     
            proxy_redirect off;
        }  

        location ~*  \.(jpg|jpeg|png|gif|ico|css|js|svg)$ {
            expires 365d;
        }
    }

What I want to achieve is that site2 must have its dedicated ip and when domain requested it must resolve site2.

But right now with that configuration it always open site1.

I added default_server thinking that site2 is not resolved properly and that is why opened site1. But after I added default_site server section it continued to open site1 when site2 domain requested.

Any help appreciated.

New contributor
Ahmed is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • 1
    Does site2.com resolve to the IP address you want? When checking open ports with netstat -tuplan, does nginx correctly bind itself to all IP addresses / ports? – Tero Kilkanen 2 days ago

Your Answer

Ahmed is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.