修改nginx中php的后辍名文件名

14 篇文章 0 订阅

由于有一个项目的某个功能逻辑需要回调(项目组提供给第三方接口的地址),但某同事提供了一个html结尾的回调地址。由于某种原因回调地址不能更改。
无奈之下,想出了一个办法那就是修改nginx原来匹配php的地方改为html。

nginx配置:

server
{
    listen 80;
    server_name www.test.com test.com;
    index index.html index.htm index.php;
    root  /home/wwwroot/test/;

    #error_page   404   /404.html;

    location ~ [^/]\.html(/|$)
    {
        try_files $uri =404;
        fastcgi_pass  unix:/tmp/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }

    location /nginx_status
    {
        stub_status on;
        access_log   off;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }

    location ~ /\.
    {
        deny all;
    }

    access_log  /home/wwwlogs/access.log  access;
}

然后保存nginx配置,并重启nginx

但访问的时候发现:Access denied.

开始我以为是文件权限问题,跑了一大圈,什么该用户所属啊之类。

但最终发现是php的配置问题:
修改:/usr/local/php/etc/php-fpm.conf
在最后的位置加上:security.limit_extensions = .php .html

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
security.limit_extensions = .php .html

重启php-fpm即可访问。


还有一种情况就是项目的文件还是php扩展名,但想访问的时候要求改成html。
那就改nginx的配置,新增一个rewrite即可:

server
{
    listen 80;
    server_name www.test.com test.com;
    index index.html index.htm index.php;
    root  /home/wwwroot/test/;

    #error_page   404   /404.html;
    if (!-e $request_filename)
    {
        rewrite ^\/(.*)\.html$ /$1.php last;
        break;
    }

    location ~ [^/]\.php(/|$)
    {
        try_files $uri =404;
        fastcgi_pass  unix:/tmp/php-cgi.sock;
        fastcgi_index index.php;
        include fastcgi.conf;
    }

    location /nginx_status
    {
        stub_status on;
        access_log   off;
    }

    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }

    location ~ /\.
    {
        deny all;
    }

    access_log  /home/wwwlogs/access.log  access;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值