Nginx CodeIgniter删除URL中的index.php
作者:互联网
我有一个安装了CentOS 6.5 Plesk 11.5的专用服务器,我已经打开Nginx来处理PHP文件.
我在Plesk工具/服务管理中打开了服务:
>反向代理服务器(nginx)
> PHP-FPM支持nginx
并在Domains / example.com / Web服务器设置中
>智能静态文件处理
>通过nginx直接提供静态文件
>通过nginx处理PHP
我使用CodeIgniter Framework,一切都适用于默认配置.但是当我尝试删除CodeIgniter配置文件中的index.php时(config.php)
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
以前的URL example.com/project/index.php/text变成了example.com/project/text但我无法访问链接并出现以下错误:
No input file specified.
我搜索过,有很多解决方案,没有什么对我有用. Plesk自动为每个域生成Nginx配置.根据指南,我尝试在Domains / example.com / Web Server Settings中的附加nginx指令中添加此代码.
location ~ /project {
try_files $uri $uri/ /index.php?$args;
}
我得到一个不同的错误:
File not found.
我应该改变什么,在哪里?我浪费了2天没有成功.
我在example.com.conf中有以下代码,但它是由Plesk自动生成的.
server {
listen IP_IS_HIDDEN:80;
server_name domain.com;
server_name www.example.com;
server_name ipv4.example.com;
client_max_body_size 128m;
root "/var/www/vhosts/example.com/httpdocs";
access_log /var/www/vhosts/system/example.com/logs/proxy_access_log;
if ($host ~* ^www.example.com$) {
rewrite ^(.*)$http://example.com$1 permanent;
}
location / {
proxy_pass http://IP_IS_HIDDEN:7080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log off;
}
location @fallback {
proxy_pass http://IP_IS_HIDDEN:7080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log off;
}
location ~ ^/plesk-stat/ {
proxy_pass http://IP_IS_HIDDEN:7080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log off;
}
location ~ ^/(.*\.(ac3|avi|bmp|bz2|css|cue|dat|doc|docx|dts|exe|flv|gif|gz|htm|html|ico|img|iso|jpeg|jpg|js|mkv|mp3|mp4|mpeg|mpg|ogg|pdf|png|ppt|pptx|qt|rar|rm|swf|tar|tgz|txt|wav|xls|xlsx|zip))${
try_files $uri @fallback;
}
location ~ ^/~(.+?)(/.*?\.php)(/.*)?${
alias /var/www/vhosts/example.com/web_users/$1/$2;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix:/var/www/vhosts/system/example.com/php-fpm.sock";
include /etc/nginx/fastcgi.conf; }
location ~ ^/~(.+?)(/.*)?${
proxy_pass http://IP_IS_HIDDEN:7080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
access_log off;
}
location ~ \.php(/.*)?${
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix:/var/www/vhosts/system/example.com/php-fpm.sock";
include /etc/nginx/fastcgi.conf; }
location ~ /${
index index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml;
}
include "/var/www/vhosts/system/example.com/conf/vhost_nginx.conf";
}
解决方法:
我终于解决了重写问题.重要的是,Plesk在Nginx配置文件中生成默认参数,该文件中的任何更改都是临时的.
要删除CodeIgniter项目中的index.php,只需在Plesk>域/示例/ Web服务器设置中为每个项目添加此代码:
location /category/subcategory {
try_files $uri $uri/ /category/subcategory/index.php;
}
并删除CodeIgniter config.php中的index.php参数:
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
标签:nginx,codeigniter,plesk 来源: https://codeday.me/bug/20190717/1490882.html