nginx 超时配置、根据域名、端口、链接 配置不同跳转
Location正则表达式
location的作用
location指令的作用是根据用户请求的URI来执行不同的应用,也就是根据用户请求的网站URL进行匹配,匹配成功即进行相关的操作。
location的语法 已=开头表示精确匹配 如 A 中只匹配根目录结尾的请求,后面不能带任何字符串。 ^~ 开头表示uri以某个常规字符串开头,不是正则匹配 ~ 开头表示区分大小写的正则匹配; ~* 开头表示不区分大小写的正则匹配 / 通用匹配, 如果没有其它匹配,任何请求都会匹配到
根据域名判断跳转不同服务
#当客户端访问www.a393060727.com,监听端口号为80,直接跳转到data/www目录下文件
server {
listen 80;
server_name www.a393060727.com;
location / {
root data/www;
index index.html index.htm;
}
}
#当客户端访问bbs.a393060727.com,监听端口号为80,直接跳转到data/bbs目录下文件
server {
listen 80;
server_name bbs.a393060727.com;
location / {
root data/bbs;
index index.html index.htm;
}
}根据端口判断跳转不同服务
#当客户端访问www.a393060727.com,监听端口号为8080,直接跳转到data/www目录下文件
server {
listen 8080;
server_name 8080.a393060727.com;
location / {
root data/www;
index index.html index.htm;
}
}
#当客户端访问www.a393060727.com,监听端口号为8081,直接跳转到data/bbs目录下文件
server {
listen 8081;
server_name 8081.a393060727.com;
location / {
root data/bbs;
index index.html index.htm;
}
}根据链接不同,跳转不同地址服务器
### 服务创建监听的端口号
server {
##监听的端口号
listen 80;
### 服务名称
server_name www.a393060727.com;
#### 匹配URL路径地址 /表示匹配所有路径地址 默认不区分大小写
###location / {
### root html;
### index index.html index.htm;
### }
### 表示 /后面的路径地址不能带任何字符串 www.a393060727.com/userNamne
## location =/ {
### root html;
### index index.html index.htm;
###}
### 匹配项目名称为tomcat_8080开头
location /tomcat_8080/ {
### 配置反向代理
proxy_pass http://127.0.0.1:8080/;
index index.html index.htm;
}
### 匹配项目名称为tomcat_8081开头
location /tomcat_8081/ {
### 配置反向代理
proxy_pass http://127.0.0.1:8081/;
index index.html index.htm;
}
} 相关推荐
byourb 2019-12-18
SZStudy 2020-07-04
scaleqiao 2020-10-22
Neptune 2020-07-04
ssihc0 2020-06-14
某些公司会墙特定网站,如果你有一个可访问的域名和服务器,就可以通过nginx反向代理来来解决这些问题。比如现在我们用mirror.example.com镜像www.baidu.com,以下是详细操作。
byourb 2020-06-05
阳光岛主 2020-06-01
itmale 2020-05-26
岁月如歌 2020-05-19
Strongding 2020-05-12
咻咻ing 2020-03-23
wvfeng 2020-04-16
岁月如歌 2020-04-15
carolAnn 2020-04-14
Strongding 2020-04-08
ysmh00 2020-03-27
APCDE 2020-02-21