Are there any issues related to IP access after nginx domain name resolution? ?
PHP中文网
PHP中文网 2017-06-06 09:54:39
0
1
804

The existing domain name test.com purchased from Wanwang has been resolved to ip and is 192.168.2.106 Alibaba Cloud linux server On the server, the directory path is A, and the server is also configured with the hosts file.

hosts

127.0.0.1 test.com

Now there is a need to access another website on the server 192.168.2.106 through IP (linux local domain name is csp.com), and the target directory is B, and does not affect the normal use of the test.com website, the hosts configuration file is as follows:

192.168.2.106 csp.com

The result is that using ip to access the csp.com website in the directory B, using the domain name test.com When I visit, I also visit the website csp.com with the directory B, which is frustrating.

How to implement, ip access, access the csp.com website in the directory B, use the domain name test.com to access , are you accessing the website test.com with the directory A? ?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
阿神

If you have configured domain name resolution, the configuration of hosts, especially the hosts configuration on the server is redundant

The simplest solution is to use two vhosts

nginx’s plan is as follows

server {
    listen 80;
    server_name test.com
    root A;
    # 其它定制配置
}

server {
    listen 80 default_server; # default_server 表示默认规则
    server_name csp.com _; # _ 表示如果没有其它任何名称匹配, 将走到这里
    root B;
    # 其它定制配置    
}

For details, please see: https://www.nginx.com/resource...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template