由于有一个项目的某个功能逻辑需要回调(项目组提供给第三方接口的地址),但某同事提供了一个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;
}