nginx配置虚拟主机之不同端口和不同IP地址
2015-12-19 20:17
701 查看
配置nginx虚拟主机不同端口和不同ip地址,和上编nginx基于域名配置虚拟主机博文类似,请先参考。
zxl.com域名不同端口,配置文件内容如下:
不同ip地址的虚拟主机配置,添加ip地址以及配置文件如下:
ip地址192.168.33.132配置文件内容
本文出自 “村里的男孩” 博客,请务必保留此出处http://noodle.blog.51cto.com/2925423/1726416
zxl.com域名不同端口,配置文件内容如下:
[root@zxl-nginx conf.d]# cat zxl.com.conf server { listen 81; server_name www.zxl.com zxl.com; location / { root /data/zxl; index index.html index.htm; access_log logs/zxl.access.log; error_log logs/zxl.error.log; } }bbs.com域名不同端口,配置文件内容如下:
[root@zxl-nginx conf.d]# cat bbs.com.conf server { listen 82; server_name www.bbs.com bbs.com; location / { root /data/bbs; index index.html index.htm; access_log logs/bbs.access.log; error_log logs/bbs.error.log; } }nginx端口查看,检测语法以及重新加载配置文件到内存中
[root@zxl-nginx conf.d]# netstat -nplt|grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3476/nginx tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 3476/nginx tcp 0 0 0.0.0.0:82 0.0.0.0:* LISTEN 3476/nginx [root@zxl-nginx conf.d]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@zxl-nginx conf.d]# nginx -s reload测试结果如下:
[root@zxl-nginx conf.d]# elinks http://www.zxl.com:81 --dump This is a site www.zxl.com test! [root@zxl-nginx conf.d]# elinks http://www.bbs.com:82 --dump This is a site www.bbs.com test!
不同ip地址的虚拟主机配置,添加ip地址以及配置文件如下:
[root@zxl-nginx conf.d]# ifconfig eth0:1 192.168.33.132 [root@zxl-nginx conf.d]# ifconfig eth0:2 192.168.33.133查看配置ip地址
[root@zxl-nginx conf.d]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:50:56:32:9b:32 brd ff:ff:ff:ff:ff:ff inet 192.168.33.131/24 brd 192.168.33.255 scope global eth0 inet 192.168.33.132/24 brd 192.168.33.255 scope global secondary eth0:1 inet 192.168.33.133/24 brd 192.168.33.255 scope global secondary eth0:2 inet6 fe80::250:56ff:fe32:9b32/64 scope link valid_lft forever preferred_lft forever不同ip地址的虚拟主机配置文件如下:
ip地址192.168.33.132配置文件内容
[root@zxl-nginx conf.d]# cat zxl.com.conf server { listen 192.168.33.132:80; server_name www.zxl.com zxl.com; location / { root /data/zxl; index index.html index.htm; access_log logs/zxl.access.log; error_log logs/zxl.error.log; } }ip地址192.168.33.133配置文件内容
[root@zxl-nginx conf.d]# cat bbs.com.conf server { listen 192.168.33.133:80; server_name www.bbs.com bbs.com; location / { root /data/bbs; index index.html index.htm; access_log logs/bbs.access.log; error_log logs/bbs.error.log; } }检测nginx配置文件以及重新加载nginx
[root@zxl-nginx conf.d]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@zxl-nginx conf.d]# nginx -s reload
测试结果如下: [root@zxl-nginx conf.d]# elinks http://192.168.33.132 --dump #This is a site www.zxl.com test! This is a site 192.168.33.132 test! [root@zxl-nginx conf.d]# elinks http://192.168.33.133 --dump #This is a site www.bbs.com test! This is a site 192.168.33.133 test!
本文出自 “村里的男孩” 博客,请务必保留此出处http://noodle.blog.51cto.com/2925423/1726416
相关文章推荐
- nginx配置虚拟主机之基于域名
- nginx使用问题记录
- nginx1.8编译安装
- Nginx 权威解读
- nginx的gzip压缩功能的配置
- Nginx学习之六-nginx核心进程模型
- Nginx源码分析-启动初始化过程(一)
- nginx Makefile中添加编译自定义模块
- nginx性能优化技巧
- Nginx学习笔记二 -- nginx的配置
- Nginx学习笔记一
- 整理下ubuntu系统下用symfony新建web项目的环境搭建以及一些问题
- 为PHP设置服务器(Apache/Nginx)环境变量
- zabbix监控nginx 状态
- Apache与Nginx的优缺点
- 源码安装nginx
- nginx与zookeeper交互,同步数据,发送系统负载信息。
- nginx fastcgi_param导致页面空白
- nginx.conf
- /etc/init.d/ nginx脚步启动文件