我已将我的文件(Codeigniter Framework)上传到abcd目录(url:example.com/abcd)。内部的所有链接都给出404错误。为了删除index.php,我将这个nginx.conf文件放在我的根目录中(在服务器上:/.../abcd/) 以下是nginx.conf文件的代码:
server {
server_name example.com/abcd;
root /..../abcd;
index index.html index.php index.htm;
# set expiration of assets to MAX for caching
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location / {
# Check if a file exists, or route it to index.php.
try_files $uri $uri/ /index.php;
}
location ~* \.php$ {
fastcgi_pass example.com/abcd;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
在apache中,使用重写很容易,我现在坚持使用nginx。请帮忙,我是第一次使用nginx
答案 0 :(得分:0)
尝试以下代码..取自 https://serverfault.com/questions/695521/codeigniter-in-subdirectory-on-nginx-404
location /abcde/ {
alias /var/www/abcde/;
try_files $uri $uri/ /abcde/index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_pass backend;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}