It's a simple question of nginx configuration, but why can't you access the specific page?

for example, when I first used nginx, I changed it according to the default configuration and wanted to do a simple hello world..

The expected effect of

is that typing http://aaa.com:8081/main.html, in the browser address bar should open a specific page. But the reality is so cruel that the browser simply says "unable to access this site".

therefore, I would like to ask what went wrong and how to solve it. Why is it that when I change the server_name in the configuration to localhost, the access is normal?

the configuration file code is as follows: nginx.conf

-sharpuser  nobody;
worker_processes  1;

error_log  logs/error.log;
error_log  logs/error.log  notice;
error_log  logs/error.log  info;

events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

 -sharp 
    server {
        listen       8081;
        server_name  aaa.com;   -sharplocalhost

        location / {
            root   html;
            index  main.html index.html;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    include servers/*;
}

actual effect:
1. Enter localhost:8081/main.html is normal

clipboard.png
2.aaa.com:8081/main.html

clipboard.png

Jun.24,2021

check whether the DNS resolution of aaa.com on your computer is your Nginx server


the ip that you enter localhost is: 127.0.0.1.
you enter aaa.com to resolve aaa.com the ip, of this domain name will go to DNS to find the domain name.
if you want to access aaa.com to your nginx on your computer, you need to configure aaa.com in the host file to point to 127.0.0.1


in host configuration, so that dns parsing will give priority to local hosts files. The hosts file path of general linux is: / etc/hosts

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf566b-3a331.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf566b-3a331.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?