nginx配置tp5的pathinfo模式并隐藏后台入口文件


server {
    listen 2223;
    server_name manage;
    access_log /data/wwwlogs/access_manage.log combined;
    root /data/wwwroot/webroot/manage/public;
    index index.html index.htm admin.php;#默认后台admin.php

    location / {
        if (!-e $request_filename) {
            rewrite ^(.*)$ /admin.php$1 last; #隐藏后台入口文件admin.php
            break;
        }
    }

    location ~ ^(.+\.php)(.*)$ {
        # try_files $uri =404;
        fastcgi_pass unix:/dev/shm/php-cgi.sock; #注意:不同系统,路由不一样
        fastcgi_index index.php;

        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(\/?.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;

        # 强制将某些非法地址交给 index.php 处理
        set $new_fastcgi_script_name $fastcgi_script_name;
        if (!-e $document_root$fastcgi_script_name) {
            set $new_fastcgi_script_name "/index.php";
        }

        fastcgi_param SCRIPT_FILENAME $document_root$new_fastcgi_script_name;
        fastcgi_param SCRIPT_NAME $new_fastcgi_script_name;
    }

    location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        if (!-e $request_filename) {
            rewrite ^/(uploads/.*)$ /pic.php?$1 last;
        }
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        expires      7d; # 缓存7天
    }

    location ~ /\.ht
    {
        deny all;
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM