您的位置:首页 > 运维架构 > Nginx

nginx配置pathinfo模式

2017-01-06 11:25 155 查看
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;

        }

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

之前设置好的php连通nginx的配置
[b]location ~ \.php[b]$
{

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

必须修改为下面的方式才能支持phthinfo
[b][b]location ~ \.php(.*)[b]${

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            [b][b][b][b][b]fastcgi_param[/b][/b][/b][/b][/b] 
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;

             #[b][b][b][b][b]这里是配置[/b][/b][/b][/b][/b]重写 
就是把地址的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; 
[/b][/b][/b][/b][/b][/b]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: