您好我的网站使用nginx时遇到了很多麻烦。我的网站基于Yii框架,并启用了干净的网址格式。
问题的一个实例是搜索栏。搜索表单的操作网址为/Site/index.php/real/search
。搜索后,我被重定向到http://localhost/Site/index.php/index.php/real/view/id/4
。现在这是问题所在。 Nginx以某种方式在url中添加了额外的index.php。
因此页面不会加载任何css或js,并且以简单的html显示,并且有大量错误。
页面的实际网址为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重写正确的网址,我已经试图找到一个正确的配置几周,但没有任何成功。我将不胜感激。
谢谢, MAXX
答案 0 :(得分:0)
为什么没有添加showScriptName =&gt;假?这是我的配置
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