将PHP重写站点转换为nginx和PHP5-FPM

时间:2015-12-28 06:33:20

标签: php nginx reverse-proxy

我正在我自己的虚拟服务器上为客户端托管一个站点,这些服务器当前正在运行Apache2。我非常希望切换到nginxphp5-fpm,但我正在麻烦地正确转换网站的.htaccess文件。 (我没有自己创建网站或.htaccess,为了让事情变得更有趣,它也会进行网址重写。

因此.htaccess文件如下所示:

RewriteEngine on
RewriteRule ^search.php(/|$) - [L,NC]
RewriteRule ^admin(/|$) - [L,NC]
RewriteRule ^blog/author/([^/\.]+)/? index.php?page=blog&filter=author&query=$1 [L,QSA]
RewriteRule ^blog/date/([^/\.]+)/([^/\.]+)/? index.php?page=blog&filter=date&year=$1&month=$2 [L,QSA]
RewriteRule ^blog/date/([^/\.]+)/? index.php?page=blog&filter=date&year=$1 [L,QSA]
RewriteRule ^blog/article/([^/\.]+)/? index.php?page=blog&newsId=$1 [L,QSA]
RewriteRule ^blog/([^/\.]+)/?$ index.php?page=blog&list=$1 [L,QSA]
RewriteRule ^blog/$ index.php?page=blog [L,QSA]
RewriteRule ^download/([^/\.]+) download.php?id=$1 [L]
RewriteRule ([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&sub=$2 [L,QSA]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L,QSA]

我已设法使用以下配置在<{1}}中使用几乎网站:

nginx

这使得一些网站工作。例如,server { listen 80; server_name the-website-com; # Tell Nginx and Passenger where your app's 'public' directory is root /home/web; index index.php; if (!-e $request_filename) { rewrite ^(.+)$ /index.php?q=$1 last; } location /blog { rewrite ^/blog/author/([^/\.]+)/? /index.php?page=blog&filter=author&query=$1 last; rewrite ^/blog/date/([^/\.]+)/([^/\.]+)/? /index.php?page=blog&filter=date&year=$1&month=$2 last; rewrite ^/blog/date/([^/\.]+)/? /index.php?page=blog&filter=date&year=$1 last; rewrite ^/blog/article/([^/\.]+)/? /index.php?page=blog&newsId=$1 last; rewrite ^/blog/([^/\.]+)/?$ /index.php?page=blog&list=$1 last; } location = /blog { rewrite ^(.*)$ /index.php?page=blog last; } location /download { rewrite ^/download/([^/\.]+) /download.php?id=$1 last; } location / { rewrite ([^/\.]+)/([^/\.]+)/?$ /index.php?page=$1&sub=$2 last; rewrite ^/([^/\.]+)/?$ /index.php?page=$1 last; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /opt/nginx/conf/fastcgi.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 很好,但由于某种原因,/contact-us完全错误并尝试下载PHP文件而不是渲染它。

/our-approach中代理PHP内容时,我是一个Rails人和一些菜鸟。非常感谢任何帮助!

0 个答案:

没有答案