Nginx Location指令URI匹配规则详解

该博客详细介绍了Nginx服务器配置文件的设置,包括监听端口、服务器名称、根目录设定、文件索引及重定向规则。特别强调了自定义变量的使用,如`php_root`和`pic_root`,以及针对不同路径的location规则,用于处理静态资源、API请求和PHP文件。此外,还提到了expires指令和try_files机制,以优化缓存和文件查找。
摘要由CSDN通过智能技术生成
server {
    listen 80;
    server_name ss.test *.ss.test;
    root "D:/Project/PHP/admin-h5/dist/";
	set $php_root "D:/Project/PHP/admin/src/public/";
	set $pic_root "D:/Project/PHP/admin/src/storage/app/";
    
    index index.html index.htm index.php;
 
    location / {
        expires -1;
        index index.html;
        try_files $uri /index.html break;
    }
	
    location ~ /swagger-ui-assets {
       index index.php;
       try_files $uri $uri/ /index.php?$query_string;
    }
	
	#location ~ /docs-api {
	location ~ /docs-.+$ {
       index index.php;
       try_files $uri $uri/ /index.php?$query_string;
    }
	
	location ~ /.+/documentation$ {
       index index.php;
       try_files $uri $uri/ /index.php?$query_string;
    }
	
	location ^~ /api {
        index index.php;
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php$ {
		root $php_root;
        include snippets/fastcgi-php.conf;
        fastcgi_pass php_upstream;		
        #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }
	
	location ^~ /uploads {
		root $pic_root;
    }
	
	
    charset utf-8;
	
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    location ~ /\.ht {
        deny all;
    }
}

自定义变量,正则匹配

参考:https://blog.csdn.net/xyang81/article/details/51989079

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值