在google里还是其他搜索引擎查找nginx绑定独立IP的信息都没找到. google也有不懂的东西嘛,哈.
最后还是查看nginx官方文档才得以解决.一般nginx添加网站后默认是这样的(官方示例):
http { server { listen 80; server_name www.domain1.com; access_log logs/domain1.access.log main; location / { index index.html; root /var/www/domain1.com/htdocs; } } server { listen 80; server_name www.domain2.com; access_log logs/domain2.access.log main; location / { index index.html; root /var/www/domain2.com/htdocs; } } }
很多朋友说要绑定独立IP直接这样写:
listen 69.164.196.163:80;
假如添加一个网站这样是没问题的,但如果你添加两个网站那么问题就来了,会提示端口被占用的错误.所以这样“IP:端口 “的写法对于多网站多IP显然是行不通的.查看了官方文档得出了答案,官方地址为:http://wiki.nginx.org/NginxHttpCoreModule#listen
写法有如下几种
listen 127.0.0.1:8000; listen 127.0.0.1; listen 8000; listen *:8000; listen localhost:8000;
但是看到官方说If only address is given, the default port is 80.也就是跟”IP:端口”是一样的道理,但加上端口就不行,去掉端口就OK,很是奇怪,不过最终问题得以解决.直接这样写就OK 了
listen 69.164.196.163;
liste 1.2.3.4:80 default;
这样写最好~如果有多个域名绑定同一IP的话,这样写可以绑定IP