0

我刚切换到 nginx,但我的 URL 重写遇到了问题

我用了

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

}

4

2 回答 2

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

玩得开心 !

于 2012-11-26T07:51:56.997 回答
1

你读过文档吗?

休息->最后

location /id/ {
    rewrite ^/id/(.*)$ /index.php?id=$1 last;
}
于 2012-11-26T19:48:38.850 回答