0

I have installed nginx on a VM (OS: Ubuntu 18). I am following this tutorial but the issue is that I am not able to see the content getting served on your_domain.com. Here's my nginx.conf:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # SSL Settings
        ##

        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
        ssl_prefer_server_ciphers on;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # Virtual Host Configs
        ##

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}


#mail {
#       # See sample authentication script at:
#       # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#       # auth_http localhost/auth.php;
#       # pop3_capabilities "TOP" "USER";
#       # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#       server {
#               listen     localhost:110;
#               protocol   pop3;
#               proxy      on;
#       }
# 
#       server {
#               listen     localhost:143;
#               protocol   imap;
#               proxy      on;
#       }
#}

Files in sites-enabled and sites-available directory: default your_domain your_domain (both in sites-enabled and sites-available)

server {
        listen 80;
        listen [::]:80;

        root /var/www/your_domain/html;
        index index.html index.htm index.nginx-debian.html;

        server_name your_domain.com www.your_domain.com;

        location / {
                try_files $uri $uri/ =404;
        }
}

index.html file in /var/www/your_domain/html

<html>
    <head>
        <title>Welcome to your_domain!</title>
    </head>
    <body>
        <h1>Success!  The your_domain server block is working!</h1>
    </body>
</html>

Lastly, this is my /etc/hosts

127.0.0.1 localhost
127.0.0.1 your_domain.com (trying out)
35.188.213.229 your_domain.com (trying out)
10.128.0.48 your_domain.com (trying out)

I am not sure where the issue is because whenever I open your_domain.com, it says the following in chrome browser

This site can’t be reached your_domain.com’s server IP address could not be found.

I have tried doing traceroute your_domain.com as well:

traceroute: unknown host your_domain.com

Tried nginx in macOS, it works there but I need to set it up in ubuntu VM for my project.

James Z
  • 12,209
  • 10
  • 24
  • 44
sinwon
  • 1
  • 1

1 Answers1

0

Given that traceroute is unable to resolve host name into ip address, I suppose that problem is caused by your /etc/hosts or some other issues with name resolution process on client side.

Most probably linux resolver library is unhappy with () in lines. Try removing them, keeping statement as clean as possible - e.g.:

127.0.0.1 your_domain.com

Note - this thing may be cached, so you may also need to restart your browser after making changes.

On MacOS you may even need to flush system-level dns cache:

dscacheutil -flushcache && killall -HUP mDNSResponder
mickvav
  • 310
  • 2
  • 6
  • Yep I'm not using (), put them here just to explain. But do you think running nginx server block on VM, i should give the IP address this 127.0.0.1 and not the primary IP address of my VM? – sinwon Jan 30 '23 at 09:24
  • Depends on which /etc/hosts we are speaking about and how your vm is connected to your hosts. On vm itself, it's ok and even advisable to have 127.0.0.1 - if you wish your http client on vm to be able to reach your nginx no-matter-what. Basically if `curl http://your_domain.com` on vm gives you correct page - your nginx is almost certainly tuned correctly. On host system - if your VM is hidden behind nat (and not pingable on it's ip), _and_ you've created tcp forwarding rules to forward some ports into vm - it is also ok. – mickvav Jan 30 '23 at 09:33
  • If your vm is bridged to the same network as your host (and thus you can ping it's ip address from host), on the other hand - you should use that ip address instead of 127.0.0.1 – mickvav Jan 30 '23 at 09:34