nginx配置pathinfo模式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35480270/article/details/54136035
location ~ ^/[\w\-]+\.php($|/) {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }


或者吧头部直接换成  location ~ \.php($|/) {    这样就行 

之前设置好的php连通nginx的配置
location ~ \.php${
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

必须修改为下面的方式才能支持phthinfo
location ~ \.php(.*)${
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO $1;
            include        fastcgi_params;
        }

nginx配置虚拟主机的话    只需要加上下面的配置
server{
        listen 80;   
        server_name  www.testxuli.com;
        index  index.php;
        root /usr/local/www/html;
        location / {
             root   /usr/local/www/html;
             index index.php index.html index.htm;
             #这里是配置重写  就是把地址的index.php去掉就好了
             if ( !-e $request_filename){    
                rewrite (.*)$ /index.php/$1;
             }
        }
       #  这里是配置nginx连通php并且包含了pathinfo的配置了的:
        location ~ \.php(.*)$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO $1;
            include        fastcgi_params;
        }

    }

   nginx的反向代理
    location ~\.(jpg|gif|png|jpeg){
        proxy_pass http://192.168.1.10:80;  
        proxy_set_header X-Forwarded-For $remote_addr; ##反向代理的时候  把请求的本体ip给带上
    }  
    nginx的负载均衡
    
    upstream imgserver{
        server 192.168.1.10:80 weight=1 max_fails=2 fail_timeout=30;
        server 192.168.1.11:80 weight=1 max_fails=2 fail_timeout=30;
    }
    
    负载均衡了之后  把反向代理的请求放到集群里面去就好了    
    proxy_pass http://imgserver; 



猜你喜欢

转载自blog.csdn.net/qq_35480270/article/details/54136035