• nginx 配置文件 PATHINFO重写规则


    user  www www;
    worker_processes  2;

    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;

    pid        logs/nginx.pid;


    events {
        use epoll;
        worker_connections  2048;
    }


    http {
        include       mime.types;
        default_type  application/octet-stream;

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status  "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  logs/access.log  main;

        sendfile        on;
        fastcgi_intercept_errors on;
        keepalive_timeout  65;

        #gzip  on;

        server {
            listen       80;
            server_name  *.newfangzhu.com newfangzhu.com;
            #charset utf-8;
    #    include drop_sql.conf;
            access_log  logs/host.access.log  main;
        
            location / {
                root   /home/www/web/new_fangzhu;
                index  index.html index.htm index.php;
            }

            #error_page 404 =http://www.fangzhur.com/error/error.html
            error_page   500 502 503 504 404 /error.html;
            location = /error.html {
                root   /home/www/web/new_fangzhu/error;
            }

          include /usr/local/nginx/conf/fangzhu.conf;
            location ~ .php$ {
                root           /home/www/web/new_fangzhu;
                fastcgi_pass   127.0.0.1:8000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
        
        }


        server {
            listen       80;
            server_name  test.com;
            access_log  logs/host.access.log  main;
        
            location / {
           
            root   /home/www/web/Test1/Web;
                index  index.html index.htm index.php;

            if (!-e $request_filename) {
            rewrite  ^/(.*)$  /index.php/$1  last;
            break;
            }
            }

            location ~ .+.php($|/)  {
                root           /home/www/web/Test1/Web;
            set $script    $uri;
            set $path_info  "/";
                fastcgi_pass   127.0.0.1:8000;
                #fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;


                     #定义变量 $path_info ,用于存放pathinfo信息
                    set $path_info "";
                    #定义变量 $real_script_name,用于存放真实地址
                    set $real_script_name $fastcgi_script_name;
                    #如果地址与引号内的正则表达式匹配
                    if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
                            #将文件地址赋值给变量 $real_script_name
                            set $real_script_name $1;
                            #将文件地址后的参数赋值给变量 $path_info
                            set $path_info $2;
                    }
                    #配置fastcgi的一些参数
                #fastcgi_index  index.php?IF_REWRITE=1;
                #include fastcgi_params.conf;
                    fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                    fastcgi_param SCRIPT_NAME $real_script_name;
                    fastcgi_param PATH_INFO $path_info;
            }
        
        }


    }

    web开发工程师一名,喜欢研究技术,学习新技术.爱好:读书,电影,民谣,乡村音乐,相声,羽毛球,爬山,徒步,动物!
  • 相关阅读:
    文件比较运算符
    中山慧海人才市场9月份 现场招聘会预告
    80后智能科技公司诚聘业务人员
    元豪路灯厂诚聘
    对Discuz的简单认识
    discuz阅读权限的设置作用
    个人对织梦系统的认识
    awvs的用法
    cain使用方法
    CCNA笔记(1)
  • 原文地址:https://www.cnblogs.com/raffeale/p/3879398.html
Copyright © 2020-2023  润新知