0
我剛開始嘗試Nginx,但是我遇到了配置問題。我想實現以下目標:爲什麼Nginx重寫一切到index.php,不起作用?
- 我希望每一個流量重定向到
index.php
- 這樣我就可以使用路由創建乾淨的URL。
Si我想重寫URL。之前我使用的Apache與此配置:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?q=$1 [QSA,L]
這阿帕奇規則只是重定向每一個流量index.php
。我想與Nginx一樣。
到目前爲止我有這個代碼,但它並不真正wokrking。它給我502錯誤和403錯誤。
server {
error_log /var/log/nginx/vhost-error_log warn;
listen *.*.*.*:80;
listen [::]:80;
server_name ***.com www.***.com;
access_log /usr/local/apache/domlogs/***.com-bytes_log bytes_log;
access_log /usr/local/apache/domlogs/***.com combined;
root /home/***/public_html;
#location/{
location ~*.*\.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|html|htm|txt|js|css|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso)$ {
expires 1M;
try_files $uri @backend;
}
location @backend {
internal;
proxy_pass http://*.*.*.*:8081;
include proxy.inc;
include microcache.inc;
}
location ~ /\.ht {
deny all;
}
location/{
set $page_to_view "/index.php";
try_files $uri $uri/ @rewrites;
root /home/***/www/public_html/ ;
index index.php index.html index.htm;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/***/www/public_html/$page_to_view;
}
# rewrites
location @rewrites {
if ($uri ~* ^/([a-z]+)$) {
set $page_to_view "/$1.php";
rewrite ^/([a-z]+)$ /$1.php last;
}
}
}
我知道這是原始配置和我在谷歌上找到的東西的組合。任何人都可以請幫助我,我應該如何做一個可用的文件,做我需要的工作?