配置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 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

测试结果如下:

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 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配置文件内容

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 -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
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地址的更多相关文章

  1. nginx配置虚拟主机vhost的方法详解

    Nginx vhost配置,可实现基于ip.端口号.servername的虚拟主机,同时可避免直接修改主配置文件.在nginx下配置虚拟主机vhost非常方便.这篇文章主要介绍了nginx配置虚拟主机 ...

  2. nginx 配置虚拟主机

    文章转载自:http://www.ttlsa.com/html/1571.html 上篇说道我们的nginx是安装在/usr/local/nginx/ cd conf 我们现在把所有的虚拟主机放在一个 ...

  3. nginx 配置虚拟主机的三种方法

    nginx,一个server标签就是一个虚拟主机. 1.基于域名的虚拟主机,通过域名来区分虚拟主机——应用:外部网站 2.基于端口的虚拟主机,通过端口来区分虚拟主机——应用:公司内部网站,外部网站的管 ...

  4. windows 下 nginx 配置虚拟主机

    1. 在 nginx 的配置文件 nginx.conf 里面 引入虚拟主机配置文件,以后所有的虚拟主机配置文件都在写这个文件里 include       vhost.conf; (或者新建vhost ...

  5. nginx配置虚拟主机、反向代理和负载均衡

    为了实现这个功能,需要修改nginx的配置文件,将nginx.conf清理一下,使结构更清晰. worker_processes ; events { worker_connections ; } h ...

  6. nginx 配置虚拟主机访问PHP文件 502错误的解决方法

    最近配置Nginx 服务器虚拟主机 访问目录发现报502错误 百度了很多方法 都不管用  我擦 各种抓狂----- 原本Nginx配置如下: 网上找了很多方法: 查看日志   借助nginx的错误日志 ...

  7. Nginx笔记总结五:Nginx配置虚拟主机

    upstream proxy1 { server ; } upstream proxy2 { server ; } server { listen ; server_name www1.dlab.co ...

  8. nginx配置虚拟主机-端口号区分/域名区分

    Nginx实现虚拟机 可以实现在同一台服务运行多个网站,而且网站之间互相不干扰.同一个服务器可能有一个ip,网站需要使用80端口.网站的域名不同. 区分不同的网站有三种方式:ip区分.端口区分.域名区 ...

  9. nginx 配置虚拟主机( 基于端口 )

    一.创建网站目录及文件: [root@localhost data]# tree /data /data └── wwwroot ├── www.1.com_8080 │   └── index.ht ...

随机推荐

  1. SQLServer查看存储过程的方法

    使用 sp_helptext 查看存储过程的定义 在对象资源管理器中,连接到 数据库引擎实例,再展开该实例. 在工具栏上,单击“新建查询”. 在查询窗口中,输入下列语句.更改数据库名称和存储过程名称以 ...

  2. python 类属性 、实例属性,可变数据结构作为类属性需要注意的地方

    1.一些经典的python错误不去阅读和不重视,就会把错误的做法带入到实际项目中来,甚至造成难以排查问题. 2.有一个大笨猪,按java写观察者模式,java写得是直接在类名下声明一个实例属性(不加s ...

  3. MongoDB中的聚合操作

    根据MongoDB的文档描述,在MongoDB的聚合操作中,有以下五个聚合命令. 其中,count.distinct和group会提供很基本的功能,至于其他的高级聚合功能(sum.average.ma ...

  4. Android中显示照片的Exif信息

    package com.hyzhou.pngexifdemo; import android.media.ExifInterface; import android.os.Bundle; import ...

  5. RESTFul basic introduction

    http://www.ruanyifeng.com/blog/2011/09/restful.html

  6. RAC的搭建(二)--创建ASM磁盘

     1. 规划 表决磁盘: 1Gx3(3节点以下,建议都采用这种配置,三个磁盘加起来要大于1.8G,否则会报错) 数据磁盘: 10Gx1 闪回磁盘: 5Gx1 2. 创建共享磁盘 virtualBox上 ...

  7. Kafka producer拦截器(interceptor)

    Producer拦截器(interceptor)是个相当新的功能,它和consumer端interceptor是在Kafka 0.10版本被引入的,主要用于实现clients端的定制化控制逻辑. 对于 ...

  8. codeforces水题100道 第七题 Codeforces Round #270 A. Design Tutorial: Learn from Math (math)

    题目链接:http://www.codeforces.com/problemset/problem/472/A题意:给你一个数n,将n表示为两个合数(即非素数)的和.C++代码: #include & ...

  9. Java实现给定字符串的倒序输出

    1.除2判中法: public static String orderDesc(String str){ byte [] bytes = str.getBytes(); for ( int i = 0 ...

  10. Mac下安装和卸载MySQL(含配置)

     安装 首先需要下载 MySQL Community Server 下载地址:https://dev.mysql.com/downloads/mysql/ 进入MySQL的下载界面(https://d ...