Home  >  Q&A  >  body text

How to configure nginx so that certain domain names point to local directories?

I am new to nginx and I don’t quite understand the terminology and configuration of the document. I would like to ask everyone here.

There is the following nginx configuration, and you want to point domain names such as my.domain.com to the local directory /usr/www/. I have reloaded the configuration file through nginx -s reload and still cannot point to the directory and display it when accessing http://my.domain.com.

server {
    listen       80;
    server_name  my.domain.com;
    index  index.html index.htm;
    
    autoindex on;
    autoindex_exact_size on;
    autoindex_localtime on;

    location / {
        root   /usr/www/;
    }
}

Try to replace the domain name with the real corresponding IP address, but it doesn't work either.

Of course it will take effect if server_name is set to localhost.

It has been ensured that the host does not redirect the domain name. (By the way, will nginx and host conflict, or does iginx have higher priority?)

phpcn_u1582phpcn_u15822713 days ago782

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-16 17:17:46

    In the hosts file, set my.domain.com to 127.0.0.1, and then configure it in nginx

    reply
    0
  • Cancelreply