V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
xiaoyanbot
V2EX  ›  分享发现

设置 Nginx 支持 PathInfo 安全无错版

  •  
  •   xiaoyanbot · 2018-01-07 15:54:53 +08:00 · 1419 次点击
    这是一个创建于 2300 天前的主题,其中的信息可能已经有所发展或是发生改变。
            #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
    		 
    		location ~ [^/]\.php(/|$){
    		 
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
    
                include        fastcgi_params;		
    			
    			set $path_info "";
    			set $real_script_name $fastcgi_script_name;
    			if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
    				set $real_script_name $1;
    				set $path_info $2;
    			}
    			fastcgi_param PATH_INFO       $path_info;
    			fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
    			fastcgi_param SCRIPT_NAME     $real_script_name;
    				
            }
            
    
    2 条回复    2018-01-08 00:30:39 +08:00
    zgk
        1
    zgk  
       2018-01-07 19:48:18 +08:00 via Android
    我是这么写的,还可以判断 php 文件是否存在
    ```
    server {
    listen 80 default_server;
    server_name _;

    root /www;
    index index.html index.php;

    location ~ \.php(/|$) {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+?\.php)(.*)$;
    set $real_path_info $fastcgi_path_info;
    try_files $fastcgi_script_name =404;
    fastcgi_param PATH_INFO $real_path_info;
    include fastcgi.conf;
    }
    }
    ```
    wdd2007
        2
    wdd2007  
       2018-01-08 00:30:39 +08:00
    可以解释一下么 @xiaoyanbot
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   998 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 20:15 · PVG 04:15 · LAX 13:15 · JFK 16:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.