0

我已经为此苦苦挣扎了一段时间。我想设置一个 Wordpress 博客,使其从服务器上的“/blogname”路径而不是根目录运行。我还希望路径具有与 Wordpress 脚本所在的目录不同的名称,因为服务器本身将运行 django。

我有 Nginx 作为反向代理,我设置了 php-fpm 来运行 wordpress。这是我的 Nginx 配置文件:

http {
    include             mime.types;
    default_type        application/octet-stream;
    sendfile            on;
    keepalive_timeout   65;

    #tcp_nopush         on;
    #gzip               on;

    server {
        root         /Users/username/Dev/Wordpress/;
        index        index.php index.html index.htm;
        listen       8080;
        server_name  localhost;

        # Do not serve hidden files
        location ~ /\. {
            access_log      off; 
            log_not_found   off; 
            deny            all; 
        }

        # Static files
        location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
            expires max;
            add_header Pragma public;
            add_header Cache-Control "public, must-revalidate, proxy-revalidate";
        }

        # This is the problem
        location /blogname {
            try_files $uri $uri/ /index.php;
            rewrite  /blogname(.*) /blog$1 last;

            fastcgi_index index.php;
            fastcgi_pass  127.0.0.1:9000;
            include       fastcgi_params;
            fastcgi_param SCRIPT_FILENAME /Users/username/Dev/Wordpress/blog$fastcgi_script_name;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        }
    }
}

现在,当我访问 localhost:8080/blogname 时,我只是下载 index.php 脚本而不是执行它。

也欢迎其他提示。

4

1 回答 1

0

替换这个

location /blogname {
  try_files $uri $uri/ /index.php;
  rewrite  /blogname(.*) /blog$1 last;
  fastcgi_index index.php;
  fastcgi_pass  127.0.0.1:9000;
  include       fastcgi_params;
  fastcgi_param SCRIPT_FILENAME /Users/username/Dev/Wordpress/blog$fastcgi_script_name;
  fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}

有了这个

location ~ \.php$ {
  try_files                 $uri =404;
  fastcgi_pass              127.0.0.1:9000;
  fastcgi_index             index.php;
  fastcgi_intercept_errors  on;
  fastcgi_split_path_info   ^(.+\.php)(/.*)$;
  include                   fastcgi.conf;
}

我希望这对你有用,因为这是我用于本地服务器的。

于 2013-03-23T07:37:43.740 回答