Ami*_*min 6 php codeigniter nginx centos7
/etc/nginx/conf.d/default.conf
server{
listen 80;
listen [::]:80;
server_name 192.168.56.101 192.168.101.100 localhost;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
Run Code Online (Sandbox Code Playgroud)
我的codeigniter文件夹位于/ var / www / html / ci中的'ci',我需要什么配置来进行URL重写?...
将您的根更改为 root /var/www/html/ci
将您的 try_files 更改为 try_files $uri $uri/ /index.php?/$request_uri;
确保您的 fpm 路径 (unix:/var/run/php-fpm/php-fpm.sock;) 正确。
I didn't want to change the current document root (/var/www/html)
since my 'ci' folder is located at /var/www/html/ci.
So instead, I created a new location block in /etc/nginx/conf.d/default.conf:
server{
...
location /ci {
try_files $uri $uri/ /ci/index.php?/$request_uri;
}
...
}
Run Code Online (Sandbox Code Playgroud)
Thanks to Mert Öksüz for suggesting to use try_files $uri $uri/ /ci/index.php?/$request_uri;.