赞
踩
# 添加两个IP [root@server100 ~]# ip addr add 172.25.254.10/24 dev eth0 [root@server100 ~]# ip addr add 172.25.254.20/24 dev eth0 # 这个命令是专门用来查看IP信息的 [root@server100 ~]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP gro up default qlen 1000 link/ether 00:0c:29:19:96:ef brd ff:ff:ff:ff:ff:ff altname enp3s0 altname ens160 inet 172.25.254.100/24 brd 172.25.254.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet 172.25.254.10/24 scope global secondary eth0 valid_lft forever preferred_lft forever inet 172.25.254.20/24 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::67a0:8915:dfbb:2f8b/64 scope link noprefixroute valid_lft forever preferred_lft forever # 修改主配置文件 [root@server100 conf.d]# vim /etc/nginx/nginx.conf server { listen 80; listen [::]:80; server_name _; # root /usr/share/nginx/html; root /var/www/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location /timinglee/ { auth_basic on; auth_basic_user_file "/etc/nginx/.htpasswd"; } error_page 404 /404.html; location = /404.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } # 需要改变这一行的位置,需要把它放在server外面,http下面 include /usr/share/nginx/modules/*.conf; # 创建扩展配置文件配置虚拟主机 [root@server100 conf.d]# vim /etc/nginx/conf.d/vhosts.conf # 配置内容如下 server { listen 172.25.254.10:80; root /usr/share/nginx/virtual/10; index index.html; } server { listen 172.25.254.20:80; root /usr/share/nginx/virtual/20; index index.html; } # 创建对应目录以及创建网页文件 [root@server100 conf.d]# mkdir -p /usr/share/nginx/virtual/{10,20} [root@server100 conf.d]# echo "10" > /usr/share/nginx/virtual/10/index.html [root@server100 conf.d]# echo "20" > /usr/share/nginx/virtual/20/index.html # 访问测试 [root@server100 conf.d]# curl 172.25.254.10 10 [root@server100 conf.d]# curl 172.25.254.20 20
# 配置扩展配置文件 [root@server100 conf.d]# vim /etc/nginx/conf.d/vhosts.conf server { listen 172.25.254.10:80; root /usr/share/nginx/virtual/10; index index.html; } server { listen 172.25.254.20:80; root /usr/share/nginx/virtual/20; index index.html; } # 主要是下面这两段 server{ listen 80; server_name news.shanxin.org; root /usr/share/nginx/virtual/shanxin/news; index index.html; } server{ listen 80; server_name bbs.shanxin.org; root /usr/share/nginx/virtual/shanxin/bbs; index index.html; } # 创建对应目录以及创建网页文件 [root@server100 conf.d]# mkdir -p /usr/share/nginx/virtual/shanxin/{news,bbs} [root@server100 conf.d]# echo "news" > /usr/share/nginx/virtual/shanxin/news/index.html [root@server100 conf.d]# echo "bbs" > /usr/share/nginx/virtual/shanxin/bbs/index.html # 添加Linux系统的本机域名映射文件 [root@server100 conf.d]# vim /etc/hosts 172.25.254.100 server100.timeinglee.org www.shanxin.org news.shanxin.org bbs.shanxin.org # 访问测试 # 访问测试 [root@server100 conf.d]# curl news.shanxin.org news [root@server100 conf.d]# curl bbs.shanxin.org bbs
[root@server100 conf.d]# cat /var/log/nginx/error.log
[root@server100 ~]# tree /var/log/nginx/
/var/log/nginx/
├── access.log # 通过日志
└── error.log
0 directories, 2 files
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。