nginx怎么配置IP和域名都能访问

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx怎么配置IP和域名都能访问相关的知识,希望对你有一定的参考价值。

一个nginx服务器只能有一个虚拟主机允许IP访问
只要在server_name最后面添加一个default,就可以在其他nginx没有定义的域名下,使用当前server解析(例如,其他server都没有定义ip地址作为server_name则用IP访问会被打到default主机上)
参考技术A 1、添加server_name为空或者localhost
server
listen 80;
server_name localhost;
location /
if ($host ~ localhost)
return 403;



2、添加server_name为yourdns
server

access_log /data/logs/nginx/access.log;
listen 80;
server_name yourdns;
charset utf-8;
root /data/www;
index index.html index.htm index.php;
location /
expires 1d;

以上是关于nginx怎么配置IP和域名都能访问的主要内容,如果未能解决你的问题,请参考以下文章