[英]nginx - Rewriting wrong url values
嗨,我在讓我的網站與Nginx兼容方面遇到了很多麻煩。 我的網站基於Yii框架,並且啟用了干凈的url格式。
問題的一個例子是搜索欄。 搜索表單的操作網址為/Site/index.php/real/search
。 搜索后,我被重定向到http://localhost/Site/index.php/index.php/real/view/id/4
。 現在這是問題所在。 Nginx以某種方式在URL中添加了額外的index.php。
因此,該頁面不加載任何CSS或JS,並且以純HTML格式顯示,並且存在大量錯誤。 頁面的實際URL是http://localhost/Site/index.php/real/view/id/4
。
這是名為default.conf的Nginx服務器配置
server {
listen 80;
server_name localhost:80;
root /site;
access_log /site/access_log.log;
error_log /site/error_log.log;
index index.php;
client_max_body_size 1000M;
default_type text/html;
charset utf-8;
location = /favicon.ico {
try_files /favicon.ico =204;
}
## The main location is accessed using Basic Auth.
location / {
## Use PATH_INFO for translating the requests to the
## FastCGI. This config follows Igor's suggestion here:
## http://forum.nginx.org/read.php?2,124378,124582.
## This is preferable to using:
## fastcgi_split_path_info ^(.+\.php)(.*)$
## It saves one regex in the location. Hence it's faster.
location ~ ^(?<script>.+\.php)(?<path_info>.*)$ {
include fastcgi_params;
## The fastcgi_params must be redefined from the ones
## given in fastcgi.conf. No longer standard names
## but arbitrary: named patterns in regex.
fastcgi_param SCRIPT_FILENAME $document_root$script;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param PATH_INFO $path_info;
## Passing the request upstream to the FastCGI
## listener.
fastcgi_pass 127.0.0.1:9000;
}
## Protect these locations. Replicating the .htaccess
## rules throughout the chive distro.
location /protected {
internal;
}
location /framework {
internal;
}
## Static file handling.
location ~* .+\.(?:css|gif|htc|js|jpe?g|png|swf)$ {
expires max;
## No need to bleed constant updates. Send the all shebang in one
## fell swoop.
tcp_nodelay off;
## Set the OS file cache.
open_file_cache max=100 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
}
}
## We need to capture the case where the index.php is missing,
## hence we drop out of the path info thingie.
location ~* /([^\.])$ {
return 302 /index.php/$1;
}
## Close up git repo access.
location ^~ /.git {
return 404;
}
}
請讓我知道如何才能使nginx重寫正確的url,我已經嘗試了數周的正確配置,但沒有成功。 我將不勝感激。
謝謝,Maxx
為什么不添加showScriptName => false? 這是我的配置
用於yii框架的Nginx配置
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nodelay on;
keepalive_timeout 65;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
charset utf-8;
client_max_body_size 100m;
fastcgi_read_timeout 300;
server {
listen 80;
root /var/www/mysite/frontend/web;
server_name mysite.loc;
error_log /var/log/nginx/mysite-error.log;
access_log /var/log/nginx/mysite-access.log;
set $yii_bootstrap "index.php";
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /$yii_bootstrap?$args;
}
location ~ ^/(protected|framework|themes/\w+/views) {
deny all;
}
location ~ \.php$ {
set $fsn /$yii_bootstrap;
if (-f $document_root$fastcgi_script_name){
set $fsn $fastcgi_script_name;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fsn;
}
}
}
fastcgi_pass可以不同,例如localhost:9000,localhost:9001
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.