Khay
By:
Khay

Error while creating Virtual Host on Nginx

January 18, 2016 3.2k views
Nginx Deployment Ghost Ubuntu

Hi,

I am currently creating new virtual host on my droplet which is already installed Ghost (blog) via DigitalOcean's Ghost Application. I tried to set up virtual host using this guide, but it is not working correctly.

My root directory is under var/www . New config for sites-available is as below:

server {
        listen 80; ## listen for ipv4; this line is default and implied
        #listen [::]:80 default ipv6only=on; ## listen for ipv6

        root /var/www/test;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name arkaraung.me;
}

And also added new domain in /etc/hosts file. (let say my ip is 111.111.111.111)

111.111.111.1111 arkaraung.me

Please let me know if there is something wrong with my doing. And also please tell me what should I do. Thanks

4 comments
  • If you want to debug something you ALWAYS want to check your logs. There is usefull information inside here most of the time. Please post the nginx error log.

  • nginx error log is as below.

    2016/01/18 08:12:21 [emerg] 494#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: bind() to [::]:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: bind() to [::]:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: bind() to [::]:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: bind() to [::]:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: bind() to 0.0.0.0:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: bind() to [::]:80 failed (98: Address already in use)
    2016/01/18 08:12:21 [emerg] 494#0: still could not bind()
    2016/01/18 08:36:01 [emerg] 547#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/ghost:2
    2016/01/18 08:36:06 [emerg] 567#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/ghost:2
    2016/01/18 08:36:31 [emerg] 600#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/ghost:2
    2016/01/18 08:37:18 [emerg] 622#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/ghost:2
    2016/01/18 08:37:24 [emerg] 625#0: a duplicate default server for 0.0.0.0:80 in /etc/nginx/sites-enabled/ghost:2
    

    And this is what inside /sites-enabled/ghost file.

    server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;
    
        server_name khay.me; # Replace with your domain
    
        root /usr/share/nginx/html;
        index index.html index.htm;
    
        client_max_body_size 10G;
    
        location / {
            proxy_pass http://localhost:2368;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_buffering off;
        }
    }
    

    Thanks for your help

  • Allright, please give the output of:

    grep -r listen /etc/nginx/sites-enabled/*
    
  • @CrypticDesigns

    /etc/nginx/sites-enabled/arkaraung.me:        listen 80; ## listen for ipv4; this line is default and implied
    /etc/nginx/sites-enabled/arkaraung.me:        #listen [::]:80 default ipv6only=on; ## listen for ipv6
    /etc/nginx/sites-enabled/ghost:    listen 80 default_server;
    /etc/nginx/sites-enabled/ghost:    listen [::]:80 default_server ipv6only=on;
    
1 Answer

so you have to checck whether the apache service is running on your pc
then sudo service apache2 stop
sudo service nginx restart
because in apache we have given the same http address 80 and also in nginx is given address 80 so that it telll like that

Have another answer? Share your knowledge.