2

首先,请原谅我,因为我对 nginx 完全陌生。

单个站点,在根目录中运行 Wordpress,在子目录中运行各种其他应用程序。据我所知,Wordpress 永久链接/重写工作得很好。

问题:所有 php 文件在直接浏览时都能正常工作。但是,当访问 /apply/ 时,文件会被下载和/或在浏览器中显示为纯文本。如果我直接浏览到 /forums/apply.php,它可以正常工作。

此站点的 nginx 配置:

server_name site;
root /var/www/site;
index index.php index.html index.htm;

location /apply {
  rewrite ^/apply/ /forums/apply.php break;
}

location / {
  if (!-e $request_filename) {
    rewrite ^(.*)$ /index.php last;
    break;
  }
}


location ~ \.php {
    # for security reasons the next line is highly encouraged
    try_files $uri /index.php =404;

    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;

    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

    # if the next line in yours still contains $document_root
    # consider switching to $request_filename provides
    # better support for directives such as alias
    fastcgi_param  SCRIPT_FILENAME    $request_filename;

    fastcgi_param  REQUEST_URI        $request_uri;
    fastcgi_param  DOCUMENT_URI       $document_uri;
    fastcgi_param  DOCUMENT_ROOT      $document_root;
    fastcgi_param  SERVER_PROTOCOL    $server_protocol;

    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx;

    fastcgi_param  REMOTE_ADDR        $remote_addr;
    fastcgi_param  REMOTE_PORT        $remote_port;
    fastcgi_param  SERVER_ADDR        $server_addr;
    fastcgi_param  SERVER_PORT        $server_port;
    fastcgi_param  SERVER_NAME        $server_name;

    # If using a unix socket...
    # fastcgi_pass unix:/tmp/php5-fpm.sock;

    # If using a TCP connection...
    fastcgi_pass 127.0.0.1:9000;
}

非常感谢任何和所有建议。

4

1 回答 1

3

改变

rewrite ^/apply/ /forums/apply.php break;

rewrite ^/apply/ /forums/apply.php last;
于 2013-03-30T05:04:36.633 回答