我发现很多人和我有同样的问题,但是我找不到正确的解决方案。
我通过虚拟机和Homestead运行NGINX服务器。在生产环境中,我使用apache,因此我有一个htaccess文件:
RewriteEngine On
RewriteCond %{REQUEST_URI} !(^cms-system/public|^assets)
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ cms-system/public/$1 [L]
我使用这个htaccess重写所有的URL(除了cms-system/public和assets),指向位于cms-system/public下的index.php。我尝试使用这个工具将htaccess转换为nginx配置:https://winginx.com/en/htaccess,但效果不太好。我做了一些调整,例外规则起作用,但是无法让index.php的重写起作用。请问有人能帮帮我吗?
server {
listen 80;
listen 443 ssl http2;
server_name company.dev;
root "/home/vagrant/company/";
index index.html index.htm index.php;
charset utf-8;
location ~ ^/cms-system/public/(.*) {
}
location ~ ^/assets/(.*) {
}
location / {
if ($request_uri !~ "-f"){
rewrite ^(.*)$ /cms-system/public/$1 break;
}
}
# original location rule
# location / {
# try_files $uri $uri/ /index.php?$query_string;
# }
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/company.dev-error.log error;
sendfile off;
client_max_body_size 100m;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}
location ~ /\.ht {
deny all;
}
ssl_certificate /etc/nginx/ssl/company.dev.crt;
ssl_certificate_key /etc/nginx/ssl/company.dev.key;
}
/var/run/php/php7.0-fpm.sock
文件吗?默认的PHP-FPM池必须使用该套接字文件。 - Christos Lytras