nginx配置虚拟主机之不同端口和不同IP地址
配置nginx虚拟主机不同端口和不同ip地址,和上编nginx基于域名配置虚拟主机博文类似,请先参考。
zxl.com域名不同端口,配置文件内容如下:
|
1
2
3
4
5
6
7
8
9
10
11
|
[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域名不同端口,配置文件内容如下:
|
1
2
3
4
5
6
7
8
9
10
11
|
[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端口查看,检测语法以及重新加载配置文件到内存中
|
1
2
3
4
5
6
7
8
|
[root@zxl-nginx conf.d]# netstat -nplt|grep nginxtcp 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 -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@zxl-nginx conf.d]# nginx -s reload |
测试结果如下:
|
1
2
3
4
|
[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地址以及配置文件如下:
|
1
2
|
[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地址
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
[root@zxl-nginx conf.d]# ip a1: 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 forever2: 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配置文件内容
|
1
2
3
4
5
6
7
8
9
10
11
|
[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配置文件内容
|
1
2
3
4
5
6
7
8
9
10
11
|
[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
|
1
2
3
4
|
[root@zxl-nginx conf.d]# nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@zxl-nginx conf.d]# nginx -s reload |
|
1
2
3
4
5
|
测试结果如下:[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配置虚拟主机之不同端口和不同IP地址的更多相关文章
- nginx配置虚拟主机vhost的方法详解
Nginx vhost配置,可实现基于ip.端口号.servername的虚拟主机,同时可避免直接修改主配置文件.在nginx下配置虚拟主机vhost非常方便.这篇文章主要介绍了nginx配置虚拟主机 ...
- nginx 配置虚拟主机
文章转载自:http://www.ttlsa.com/html/1571.html 上篇说道我们的nginx是安装在/usr/local/nginx/ cd conf 我们现在把所有的虚拟主机放在一个 ...
- nginx 配置虚拟主机的三种方法
nginx,一个server标签就是一个虚拟主机. 1.基于域名的虚拟主机,通过域名来区分虚拟主机——应用:外部网站 2.基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的管 ...
- windows 下 nginx 配置虚拟主机
1. 在 nginx 的配置文件 nginx.conf 里面 引入虚拟主机配置文件,以后所有的虚拟主机配置文件都在写这个文件里 include vhost.conf; (或者新建vhost ...
- nginx配置虚拟主机、反向代理和负载均衡
为了实现这个功能,需要修改nginx的配置文件,将nginx.conf清理一下,使结构更清晰. worker_processes ; events { worker_connections ; } h ...
- nginx 配置虚拟主机访问PHP文件 502错误的解决方法
最近配置Nginx 服务器虚拟主机 访问目录发现报502错误 百度了很多方法 都不管用 我擦 各种抓狂----- 原本Nginx配置如下: 网上找了很多方法: 查看日志 借助nginx的错误日志 ...
- Nginx笔记总结五:Nginx配置虚拟主机
upstream proxy1 { server ; } upstream proxy2 { server ; } server { listen ; server_name www1.dlab.co ...
- nginx配置虚拟主机-端口号区分/域名区分
Nginx实现虚拟机 可以实现在同一台服务运行多个网站,而且网站之间互相不干扰.同一个服务器可能有一个ip,网站需要使用80端口.网站的域名不同. 区分不同的网站有三种方式:ip区分.端口区分.域名区 ...
- nginx 配置虚拟主机( 基于端口 )
一.创建网站目录及文件: [root@localhost data]# tree /data /data └── wwwroot ├── www.1.com_8080 │ └── index.ht ...
随机推荐
- 百度云高速下载Pandownload
对于一些文件大小比较小的文件,可以直接在网页分享中点击[下载]来下载: 但是,对于较大点的文件,点击[下载]会弹出百度云的桌面客户端软件来下载: 但但是,下载速度实在是太慢了,强迫症真真等不及啊~ 幸 ...
- Nginx 向客户端输出真实的后端IP地址
因为涉及到内外网的改造,所以狠多东西现在需要依赖于openresty来做总控实现.然后就碰见了一个比较难办的问题,即在upstream时候,如何获取实际处理请求的server地址.假设有如下upstr ...
- 车牌、手机、身份证、等敏感信息 屏蔽 替换 、中文转unicode编码 函数
应工作要求,需要对展示的内容进行敏感信息替换.琢磨的一些时间,编写的函数匹配率还是比较高的. 顺便说下思路,使用的是正则匹配替换和字符串替换.函数可以再改进. 先把需要匹配的内容写好相应的正则,然后进 ...
- IE8兼容性调试及IE 8 css hack
做网站开发,一提到IE,就会让人头大,有一肚子的牢骚要发:微软为什么不跟着国际标准走呢,总是独树一帜,搞出那么多问题来.IE的firebug调试工具也不太好用,尤其是低版本的IE,更是让人头疼. 最近 ...
- 【译】调优Apache Kafka集群
今天带来一篇译文“调优Apache Kafka集群”,里面有一些观点并无太多新颖之处,但总结得还算详细.该文从四个不同的目标出发给出了各自不同的参数配置,值得大家一读~ 原文地址请参考:https:/ ...
- CentOS配制FTP服务器,并且能用root权限登录
步骤如下: 1.运行yum install vsftpd命令 具体的细节如下:(如果无法更新,你先配置能访问互联网,我有文档叫 CentOS 在 VMware下,如何联网到Internet的解决办法可 ...
- java多线程例子(生成者和消费者)
Info.cs 商品 public class Info { boolean flag=false; private String name="张三"; private int a ...
- Python错误和异常 学习笔记
错误和异常概念 错误: 1.语法错误:代码不符合解释器或者编译器语法 2.逻辑错误:不完整或者不合法输入或者计算出现问题 异常:执行过程中出现万体导致程序无法执行 1.程序遇到 ...
- 《转载》IntelliJ 2016.2 IDEA 中进行 Java Web 项目开发配置
本文转载自 https://segmentfault.com/a/1190000007088964 1. 新建一个 Web Application 项目 打开 IntelliJ,选择新建项目: 左边栏 ...
- 原生js--文档加载时间
onload触发时机:文档和所有的图片都加载完毕 DOMContentLoaded触发时机:文档加载并解析完毕,所有deferred脚本执行完毕.但此时图片和async脚本可能依旧在加载. ready ...