Can server_name be set to the ip address in nginx?

in nginx, can server_name be set to the ip address?

server {

    listen 8000;
    server_name 101.20.32.76;
    
    access_log /data/ldl/logs/101.20.32.76.access.log  main;
    
    location /index01.html {
        
        alias /data/ldl/repo/QQpro/index01.html;
    }
Mar.10,2021

Yes,

If someone makes a request using an IP address instead of a server name, the "Host" request header field will contain the IP address and the request can be handled using the IP address as the server name:

authoritative notes in official documents http://nginx.org/en/docs/http.


there is no point in writing ip (here you want to follow a host name), that can write an underscore (_) or not write server_name


). Server_name sets ip to point to ip, sets localhost to point to local, and sets domain name to point to domain name


. If you use ip, it is more often used to reverse proxy to other servers. If you use ip locally to implement vhosts, you may need multiple ports.

Menu