02 nginx多站点部署
·
文章目录
准备工作
vim操作修改Nginx.conf
- 8 yy 复制8行,小p 粘贴
- 站点部署分别为/html/one, /html/two, /html/three
目录接口创建
cd /usr/share/nginx/html
mkdir {one,two,three}
echo 'one' > /html/one/index.html
echo 'two' > /html/two/index.html
echo 'three' > /html/three/index.html
1. 多端口多站点部署
同一ip配置多端口映射,实现多站点部署
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
# charset utf-8;
server {
listen 80;
server_name localhost;
location / {
root /html/one;
index index.html index.htm;
}
}
server {
listen 81;
server_name localhost;
location / {
root /html/two;
index index.html index.htm;
}
}
server {
listen 82;
server_name localhost;
location / {
root /html/three;
index index.html index.htm;
}
}
}
2. 多IP多站点部署
linux配置多个IP
ip route show #查询网关
cd /etc/sysconfig/network-scripts
[root@web01 network-scripts]# cat ifcfg-ens33
TYPE="Ethernet"
BOOTPROTO="static"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR1=192.168.22.128
IPADDR2=192.168.22.129
IPADDR3=192.168.22.130
NETMASK=255.255.255.0
GATEWAY=192.168.22.2
DNS1=223.5.5.5
systemctl restart network #ip配置完记得重启
nginx.conf
[root@web01 nginx]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
# charset utf-8;
server {
listen 192.168.22.128;
server_name localhost;
location / {
root /html/one;
index index.html index.htm;
}
}
server {
listen 192.168.22.129;
server_name localhost;
location / {
root /html/two;
index index.html index.htm;
}
}
server {
listen 192.168.22.130;
server_name localhost;
location / {
root /html/three;
index index.html index.htm;
}
}
}
3. 多域名多站点部署
- 单IP绑定多域名,访问端用hosts来解析域名
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
# charset utf-8;
server {
listen 192.168.22.128;
server_name a.monki.com;
location / {
root /html/one;
index index.html index.htm;
}
}
server {
listen 192.168.22.128;
server_name b.monki.com;
location / {
root /html/two;
index index.html index.htm;
}
}
server {
listen 192.168.22.128;
server_name c.monki.com;
location / {
root /html/three;
index index.html index.htm;
}
}
}
多IP同端口

hosts配置

更多推荐

所有评论(0)