大数据全系列 教程
1869个小节阅读:468k
目录
408考研
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
参考:
http://tengine.taobao.org/nginx_docs/cn/docs/http/ngx_http_core_module.html
语法 | location [ = | ~ | ~* | ^~ ] uri { ... }location @name { ... } |
---|---|
默认值 | - |
上下文 | server, location |
让我们用一个例子解释上面的说法:
xxxxxxxxxx
location = / {
[ configuration A ]
}
location / {
[ configuration B ]
}
location /documents/ {
[ configuration C ]
}
location ^~ /images/ {
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {
[ configuration E ]
}
请求“/”匹配配置A,
请求“/index.html”匹配配置B,
请求“/documents/document.html”匹配配置C,
请求“/images/1.gif”匹配配置D,
请求“/documents/1.jpg”匹配配置E。
修改nginx.conf配置文件
xxxxxxxxxx
server {
listen 80;
server_name www.bjsxt.cn;
access_log logs/myfmt.log myfmt;
location / {
root /mnt;
autoindex on;
}
location /aabb {
proxy_pass http://192.168.20.102:8080/;#带上/访问该url对应的首页,
#不带/ 访问http://192.168.20.102:8080/aabb
}
}
重新启动nginx
xxxxxxxxxx
[root@node1 html]# systemctl restart nginx
访问测试
扩展演示:proxy_pass http://192.168.20.102:8080/; 去掉 / 添加文件aabb
修改nginx配置文件
xxxxxxxxxx
location /baidu {
proxy_pass http://www.baidu.com/;
}
重启Nginx
xxxxxxxxxx
[root@node0 html]# systemctl restart nginx
访问www.bjsxt.cn/baidu进行测试,直接跳转到www.baidu.com首页。虽然访问到了百度,但是却是通过重定向的方式,以后发生的事情和我们的服务器就没有半毛钱关系了。优化配置nginx.conf:
xxxxxxxxxx
#尽量在服务器端跳转,不要在客户端跳转
proxy_pass https://www.baidu.com/;
重启nginx,再次测试,地址栏没有重定向,但是当我们查询(比如:ssd)时出现404
修改Nginx配置文件,然后重启
xxxxxxxxxx
location ~* /s.* {
proxy_pass https://www.baidu.com;
}
[root@node0 html]# systemctl restart nginx