我花了很长时间在谷歌上寻找任何信息,并询问了一些人(在有人建议我这样做之前)。
下面是我的 nginx.conf 中无法正常工作的部分。工作原理:重写 BlogHome、Home 和 About。
什么不起作用 - 重写为 C_ReadBlogURL 和 C_ReadAllPosts 。出于某种原因,这两个都是 404,即使路径是正确的。我不明白为什么——而且我整天都在为这个困惑。我认为这可能与它们是 php 文件有关,但我不知道。
任何帮助将不胜感激 :)
server {
listen 80;
server_name blog.example.com;
root /usr/share/nginx/www/example;
index /views/Read/BlogHome.php;
location / {
rewrite ^/?$ /views/Read/BlogHome.php last; break;
rewrite ^/(.+)/?$ /controllers/read/C_ReadBlogURL.php?url=$1 last; break;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
server {
listen 80;
server_name example.com;
root /usr/share/nginx/www/example;
index /controllers/read/C_ReadLatestPost.php;
location ~ ^(/posts\.php) {
rewrite ^(/posts\.php) /controllers/read/C_ReadAllPosts.php?type=$arg_type last; break;
}
location ~ ^/?$ {
rewrite ^/?$ /controllers/read/C_ReadLatestPost.php last; break;
}
location ~ ^(/about)/?$ {
rewrite ^(/about)/?$ /views/Read/About.php last; break;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}