VPS侦探论坛

 找回密码
 注册
查看: 9648|回复: 1

[Apache] Nginx 网站绑定独立IP

[复制链接]
发表于 2010-1-2 15:56:26 | 显示全部楼层 |阅读模式

在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;
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
 楼主| 发表于 2010-1-2 15:59:07 | 显示全部楼层
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-5-5 14:00 , Processed in 0.025040 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表