如何设置IP地址作为服务器名称的nginx?
server { listen 80; server_name xx.xx.xx.xx; location /test { root /var/www/test; } location ~ \.php$ { include /var/ini/nginx/fastcgi.conf; fastcgi_pass php; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/test$fastcgi_script_name; } }
所以我想要像这样访问服务器
http://xx.xx.xx.xx/test/ => index.php http://xx.xx.xx.xx/test/foo.php => foo.php
您可以将IP地址作为服务器名称:
server { listen 80; server_name 192.168.1.21; ... }
您可能还想要更改configuration,以仅侦听指定的IP地址:
server { listen 192.168.1.21:80; server_name 192.168.1.21; ... }
以下是来自文档: http : //nginx.org/en/docs/http/server_names.html
如果有人使用IP地址而不是服务器名称发出请求,则“主机”请求标头字段将包含IP地址,并且可以使用IP地址作为服务器名称来处理请求:
server { listen 80; server_name example.org www.example.org "" 192.168.1.1 ; ... }