[关闭]
@yanglt7 2018-10-21T15:54:16.000000Z 字数 1898 阅读 611

【Web 集群实战】09_Nginx location

Web集群实战


1. location 作用

2. location 语法

  1. location [ = | ~ | ~* | ^~ ] uri {
  2. ...
  3. }
location [ = | ~ | ~* | ^~ ] uri {...}
指令 匹配标识 匹配的网站网址 匹配 URI 后要执行的配置段

注:

3. location 匹配配置

  1. [root@ylt001 conf]# cat extra/www.conf
  2. #www virtualhost by ylt
  3. server {
  4. listen 80;
  5. server_name www.yangyangyang.org yangyangyang.org;
  6. location / {
  7. return 401;
  8. }
  9. location = / {
  10. return 402;
  11. }
  12. location /documents/ {
  13. return 403;
  14. }
  15. location ^~ /images/ {
  16. return 404;
  17. }
  18. location ~* \.(gif|jpg|jpeg)$ {
  19. return 500;
  20. }
  21. access_log logs/access_www.log main gzip buffer=32k flush=5s;
  22. }
  1. [root@ylt001 conf]# /application/nginx/sbin/nginx
  2. [root@ylt001 conf]# /application/nginx/sbin/nginx -t
  3. nginx: the configuration file /application/nginx-1.14.0//conf/nginx.conf syntax is ok
  4. nginx: configuration file /application/nginx-1.14.0//conf/nginx.conf test is successful
  5. [root@ylt001 conf]# /application/nginx/sbin/nginx -s reload
  1. [root@ylt001 conf]# /application/nginx/sbin/nginx -s reload
  2. [root@ylt001 conf]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.yangyangyang.org
  3. 402
  4. [root@ylt001 conf]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.yangyangyang.org/
  5. 402
  6. [root@ylt001 conf]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.yangyangyang.org/index.html
  7. 401
  8. [root@ylt001 conf]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.yangyangyang.org/documents/document.html
  9. 403
  10. [root@ylt001 conf]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.yangyangyang.org/images/1.gif
  11. 404
  12. [root@ylt001 conf]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.yangyangyang.org/documents/1.jpg
  13. 500
  14. [root@ylt001 conf]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.yangyangyang.org/ylt/
  15. 401
  16. [root@ylt001 conf]# curl -s -o /dev/null -I -w "%{http_code}\n" http://www.yangyangyang.org/abc/
  17. 401
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注