如何将www.example.com/posts/123转换为example.com/posts/123?

时间:2014-02-28 10:53:18

标签: php cakephp redirect nginx no-www

我正在使用在Ubuntu 12.10中运行的nginx 1.2.1

我已按照https://stackoverflow.com/a/7958540/80353

中的解决方案进行操作

所以我的虚拟现在看起来像:

server {
        listen 80;
        server_name www.example.com;
        return 301 http://example.com$request_uri;
}
server {
        listen 80;
        client_max_body_size 5M;
        server_name example.com;
        root /var/virtual/example.com/webroot;
        include common.conf;
        include php.conf;
}

不确定我做错了什么。

目前,每当我执行www.example.com/posts/123时,我都会获得302 example.com

我期待example.com/posts/123

更新:

server {
        listen 80;
        server_name www.example.com;
        rewrite ^(.*) http://example.com$1 permanent;
}
server {
        listen 80;
        client_max_body_size 5M;
        server_name example.com;
        root /var/virtual/example.com/webroot;
        include common.conf;
        include php.conf;
}

common.conf是:

index index.html;

location ~ /\.ht {
        deny all;
}

cakephp.conf是:

include php.conf;

location / {
        try_files $uri $uri/ /index.php?$uri&$args;
        expires max;
        access_log off;
}

php.conf是:

location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        include fastcgi_params;
}

index index.php;

0 个答案:

没有答案