0

有使用zend框架的网页。网络实际上使用重写。我用谷歌搜索了如何设置 zend 框架 win nginx 的解决方案。他们说没有必要将那些默认的重写 .htaccess 转换为 nginx 一个。

无论如何这里是 .htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

RewriteRule ^robots\.txt$ robots.txt

这是网页的nginx配置:

server {
    listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    root /var/www/vhosts/domain.lt/httpdocs;
    index index.php;

    # Make site accessible from http://localhost/
    server_name domain.lt;
    server_name www.domain.lt;

    location / {
        if (-f $request_filename) {
                root /var/www/vhosts/domain.lt/httpdocs;
            }   
    }

    location ~* ^/(favicon.ico|robots.txt)$ {
            access_log off;
            log_not_found off;
    }

    error_page  404 = /index.php;   

    # redirect server error pages to the static page /50x.html
    #
    #error_page 500 502 503 504 /50x.html;
    #location = /50x.html {
    #   root /usr/share/nginx/www;
    #}

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        #fastcgi_param  SCRIPT_FILENAME /var/www/vhosts/domain.lt/httpdocs/index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }

    location ~* \.(css|js|jpeg|jpg|gif|png|ico|xml)$ {
         access_log off;
         expires 30d;
    }
}

最后是错误本身:

2013/02/03 01:52:13 [error] 12293#0: *29 open() "/var/www/vhosts/domain.lt/httpdocs/daiktai/kategorija/slaugos-ir-higienos-priemones/page/147" failed (2: No such file or directory), client: 66.249.75.237, server: domain.lt, request: "GET /daiktai/kategorija/slaugos-ir-higienos-priemones/page/147 HTTP/1.1", host: "www.domain.lt"

正如您所看到的,nginx 将每次重写都视为文件条目,这当然 - 不存在。我该如何解决这个问题?网页实际上无需重写就可以很好地工作。我的问题是:如何从 error.log 中删除这些错误,我是否需要将该 htaccess 文件转换为 nginx 重写?如果可以,请转换它吗?我尝试了一些在线转换器-RewriteCond完全RewriteRule忽略了。

4

1 回答 1

0

找到解决方案:

这整个部分是错误的

 location / {
        if (-f $request_filename) {
                root /var/www/vhosts/domain.lt/httpdocs;
            }   
    }

我刚刚添加到server

 try_files $uri $uri/ /index.php;

这要location ~ \.php$

    try_files $uri =404;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;
于 2013-02-03T21:05:31.023 回答