Nginx configure different ports and different IP addresses for the virtual host

Source: Internet
Author: User

Configure Nginx Virtual host different ports and different IP addresses, and creates Macintosh Nginx based on the domain name configuration virtual Host blog similar, please refer first.

zxl.com Domain name different ports, the configuration file contents are as follows:

[email protected] 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 Domain name different ports, the configuration file contents are as follows:

[email protected] 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 Port view, detect syntax and reload config file into memory

[[email protected] 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[[email protected] 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[[email  Protected] conf.d]# nginx -s reload

The test results are as follows:

[Email protected] conf.d]# ELinks http://www.zxl.com:81--dump This is a site www.zxl.com test! [Email protected] conf.d]# ELinks http://www.bbs.com:82--dump This is a site www.bbs.com test!



Virtual host configuration for different IP addresses, add IP address and configuration file as follows:

[[email protected] conf.d]# ifconfig eth0:1 192.168.33.132[[email protected] conf.d]# ifconfig eth0:2 192.168.33.133

View the configuration IP address

[[Email protected] 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

The virtual host configuration files for different IP addresses are as follows:

IP address 192.168.33.132 configuration file contents

[email protected] 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 address 192.168.33.133 configuration file contents

[email protected] 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;}}

Detect Nginx configuration files and reload Nginx

[Email protected] conf.d]# nginx-tnginx:the configuration file/usr/local/nginx/conf/nginx.conf syntax is oknginx:conf Iguration file/usr/local/nginx/conf/nginx.conf test is successful[[email protected] conf.d]# nginx-s Reload
The test results are as follows: [[email protected] 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! [Email protected] 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!


This article is from the "Runny nose" blog, be sure to keep this source http://noodle.blog.51cto.com/2925423/1726416

Nginx configure different ports and different IP addresses for the virtual host

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.