nginx 监听一个端口多域名转发配置
www.eting.info / blog.eting.info 同时指向同一台服务器不同端口
www.eting.info -> 45.77.151.91:8080
blog.eting.info -> 45.77.151.91:9090
配置文件
1 | ➜ ~ whereis nginx |
找到 nginx.conf 配置文件
1 | ➜ nginx cat nginx.conf |
查看 -> include /etc/nginx/conf.d/.conf;
大概意思 -> 加载include /etc/nginx/conf.d;这个文件里面所有.conf配置文件
进入 conf.d文件 创建 blog.conf error.conf www.conf
1 | ➜ nginx cd conf.d |
blog.conf 1
2
3
4
5
6
7
8
9
10
11
12
13server {
listen 80;
server_name blog.eting.info;
location / {
proxy_pass http://localhost:9090;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root html;
index index.html index.htm;
}
}
error.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14server {
listen 80;
server_name 45.77.151.91;
error_page 404 401 400 /400.html;
location / {
root html;
index 400.html;
}
location = /40x.html{
root html;
}
}
www.conf1
2
3
4
5
6
7
8
9
10
11
12
13server {
listen 80;
server_name www.eting.info;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
root html;
index index.html index.htm;
}
}
重启nginx
1 | ➜ conf.d nginx -s reload |
ok
同一个文件配置 把server 都写在nginx.conf 也是可以的
1 | #user nobody; |