nginx配置默认跳转
程序员文章站
2022-05-27 23:41:43
...
1,先贴配置内容
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream cms{
server 127.0.0.1:8081;
}
upstream bus{
server 127.0.0.1:8082;
}
server {
listen 80;
server_name localhost;
location /cms {
index index;
proxy_pass http://cms ;
}
location /bus {
index index;
proxy_pass http://bus ;
}
location =/ {
rewrite / /cms;
}
}
2,以上配置分为两部分:
第一部分,upstream +项目文件夹名称 +{ 127.0.0.1+端口}
第二部分,location /路径 {}
3,默认跳转地址配置:
location =/ {
rewrite / /cms;
}
rewrite是重写的意思,比如上面的配置结果是:输入192.168.3.30会跳转到192.168.3.30/cms
4,默认跳转的另一种配置方法,直接跳转到指定文件夹的html文件
location / {
index login.html;
root /usr/local/FengShen/web;
# proxy_pass http://127.0.0.1/web;
}
5,配置多个不同的项目的方法:server{}多复制几份就可以了。
server {
listen 80;
server_name xxxx.com;
index index.html index.htm;
root /opt/zletc;
}
server {
listen 80;
server_name www.xxxxx.com;
index index.html index.htm;
root /opt/zletc;
}
server {
listen 80;
server_name xxxx.yyyyyy.com;
index index.html index.htm;
root /opt/zletc;
}
上一篇: nginx 监听端口转发
下一篇: 使用iptables实现端口转发