nginx匹配转发

找到nginx\conf\nginx.conf如下部分:
server {
listen 80;
server_name localhost;
 
#charset koi8-r;
 
#access_log logs/host.access.log main;
 
location / {
root html;
index index.html index.htm;
}
修改后如下:
server {
listen 80;
server_name painpointcloud;
 
#charset koi8-r;
 
#access_log logs/host.access.log main;
#默认静态资源
location / {
root html;
index index.html index.htm;
allow all;
}
 
#其他动态请求反向代理到tomcat容器
location ~ \.(json|do)?$ {
index index;
proxy_pass http://localhost:8080;
}
#配置[企业宣传]动态请求反向代理到tomcat容器
location ~ \.(com)?$ {
index index;
proxy_pass http://localhost:1010;
}
# 匹配任何以business开始的请求
location ^~ /business/ {
index index;
proxy_pass http://localhost:1010;
}
# 匹配任何以idea开始的请求
location ^~ /idea/ {
index index;
proxy_pass http://localhost:1010;
}
 
说明:
listen:是监听的端口,即用户访问nginx服务的端口
server_name:服务名,经过测试并不会影响到什么
location:定义资源类型与服务器中资源地址url的映射关系,可在/后面定义资源类型,可设置多个location
其中proxy_pass代表要反向代理的服务器资源url,只要资源类型匹配,在这个url下的子路径资源都可以访问到,
其中root代表本地的资源路径,同样只要资源类型匹配,这个路径下的子目录资源都可以被访问到,
一个location中只能配置一个root或proxy_pass。
 
修改后ngnix.conf文件后,使用nginx -s reload指令,重启ngnix,如果没有报错即重启成功
 
C:\Users\admin>F:
 
F:\>cd F:\develop\server\nginx
 
F:\develop\server\nginx>nginx -s reload
 
F:\develop\server\nginx>nginx -s stop
启动Nginx:start nginx

猜你喜欢

转载自blog.csdn.net/qq_26597927/article/details/80748085