2012-11-26 70 views
0

我只是切换到nginx的,但我有我的URL重写的FastCGI - 重写 - 位置与Nginx的

我用

location /id/ { 
     rewrite ^/id/(.*) /index.php?id=$1 break; 
} 

但PHP代码没有解释的麻烦,最坏它的下载生的。 然而.php文件配置如下:

location ~ \.php$ { 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
      fastcgi_param SCRIPT_FILENAME /var/www/my_app$fastcgi_script_name; 
      include /etc/nginx/fastcgi_params; 
    } 

什么是错我的虚拟主机?

编辑:这里是整个虚拟主机 服务器{

listen 80; ## listen for ipv4 
    server_name viditx.com www.viditx.com; ## change this to your own domain name 

    # I find it really useful for each domain & subdomain to have 
    # its own error and access log 
    error_log /var/log/nginx/viditx.com.error.log; 
    access_log /var/log/nginx/viditx.com.access.log; 
root /var/www/viditx; 

location/{ 
     # Change this to the folder where you want to store your website 
     index index.html index.htm index.php; 
} 
location /phpmyadmin { 
      root /usr/share/; 
      index index.php index.html index.htm; 
      location ~ ^/phpmyadmin/(.+\.php)$ { 
        try_files $uri =404; 
        root /usr/share/; 
        fastcgi_pass 127.0.0.1:9000; 
        fastcgi_index index.php; 
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
        include /etc/nginx/fastcgi_params; 
      } 
      location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { 
        root /usr/share/; 
      } 
    } 
    location /phpMyAdmin { 
      rewrite ^/* /phpmyadmin last; 
    } 


    # redirect server error pages to the static page /50x.html 
    # 
    error_page 500 502 503 504 /50x.html; 

    location = /50x.html { 
      root /var/www/nginx-default; 
    } 

    location ~ \.php$ { 
      fastcgi_pass 127.0.0.1:9000; 
      fastcgi_index index.php; 
      # again, change the directory here to your website's root directory 
      # make sure to leave $fastcgi_script_name; on the end! 
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
      include /etc/nginx/fastcgi_params; 
    } 

}

回答

1

你应该尝试:

location /id/ { 
     rewrite '^/id/(.*)$' /index.php?id=$1 break; 
} 

和:

location ~ \.php$ { 
    fastcgi_pass 127.0.0.1:9000; 
    fastcgi_index index.php; 
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include  /etc/nginx/fastcgi_params; 
} 

玩得开心!

+0

不工作。每当我去mywebsite.com/id/abc php文件仍然下载。如果这有什么帮助,我遵循本教程http://blog.meltingice.net/server-management/setting-up-a-full-web-server-with-nginx-from-start-to-finish/ – JohnT

+0

给我们你的nginx.conf plz – aulica

+0

编辑我的问题与整个虚拟主机(没有任何重写)+ conf – JohnT