2012-07-08 30 views
0

我一直在为此奋斗一段时间。我想设置一个Wordpress博客,从服务器上的“/ blogname”路径而不是根目录运行。我也希望路径具有不同的名称,然后是Wordpress脚本所在的目录,因为服务器本身将运行django。如何设置php从Nginx的单个位置运行

我有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; 
     } 
    } 
} 

现在当我访问本地主机:8080/BLOGNAME我刚刚下载的index.php脚本,而不是执行它。

其他技巧也欢迎。

回答

0

与此

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; 
} 

我希望这应该为你工作,因为这是我用我的本地服务器替换此

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; 
}