cakephp - nginx 正在从一个虚拟主机重定向到另一个

标签 cakephp redirect nginx

我的 nginx 配置有问题。 我在域 cloud.example.com 上安装了一个 owncloud,我想在 example1.com 上有另一个站点。 example1.com 上的网站是用 CakePHP 编写的,所以我为 CakePHP 网站采用了默认的 nginx 配置。我从一个德国站点获取的 owncloud 配置,它工作得很好。

但现在如果我想转到 example1.com,我将永久移动到 cloud.example.com

Google Chrome 表示:状态代码:301 永久移动(从缓存中)
我多次清除浏览器缓存和 DNS 缓存。

配置文件

example1.com

server {
    listen   80;
    server_name *.example1.com;
    return 301 http://example1.com$request_uri;
}
server {
    listen   80;
    server_name example1.com;

    # root directive should be global
    root   /var/www/example1/webroot;
    index  index.php;

    access_log /var/www/example1/log/access.log;
    error_log /var/www/example1/log/error.log;

    location / {
        try_files $uri /index.php?$args;
    }

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

自有云:

server_tokens off;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";

server {
    listen 80;
    server_name cloud.example.com;
    rewrite ^ https://$server_name$request_uri? permanent; # enforce https
}

server {
    listen 443 ssl;
    server_name cloud.example.com;
    ssl_certificate /etc/nginx/ssl/owncloud.crt;
    ssl_certificate_key /etc/nginx/ssl/owncloud.key;

        add_header Strict-Transport-Security max-age=31536000;


        root /var/www/cloud.example.com;
        index index.php;

        client_max_body_size 10G; # set max upload size
        fastcgi_buffers 64 4K;

        rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;
        rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;
        rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;

        error_page 403 = /core/templates/403.php;
        error_page 404 = /core/templates/404.php;

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
                deny all;
        }

        location / {
                rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
                rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;

                rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;
                rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;

                rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;

                try_files $uri $uri/ index.php;
        }

        location ~ ^(.+?\.php)(/.*)?$ {
                try_files $1 = 404;


                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$1;
                fastcgi_param PATH_INFO $2;
                fastcgi_param HTTPS on;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
        }

        location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
                expires 30d;
                # Optional: Don't log access to assets
                access_log off;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }

        location ~ /\.ht {
                deny all;
        }
}

最佳答案

更新 好的 - 这更有意义...... 尝试删除此 return 301 http://example1.com$request_uri;

这是告诉 NGINX 为 example1.com 域中出现的任何内容返回 301 代码。 https://en.wikipedia.org/wiki/HTTP_301 .基本上你会得到一个“永久移动”错误,因为你告诉服务器做 exactly that...;)

旧 - 由于示例文件已更改而不再相关 您是否已经尝试删除 example.com 配置中的最后一个服务器指令?

server {
    listen 80;
    server_name cloud.example.com;
    rewrite ^ https://$server_name$request_uri? permanent; # enforce https
}

关于cakephp - nginx 正在从一个虚拟主机重定向到另一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34887833/

相关文章:

ruby-on-rails - 环境变量在 DigitalOcean 中不起作用

facebook - ember.js Node 和 nginx

php - 为什么 $_SERVER ["SERVER_PROTOCOL"] 在客户端使用 HTTP/1.1 时显示 HTTP/1.0

php - 如何在 CakePHP 中访问 POST 数据然后将其删除?

php - CakePHP 中的 MySQL 连接和查询

CakePHP 不适用于共享主机 (Godaddy)

.htaccess - 是否可以同时重定向到 ssl 和非 www?

javascript - 如何通过保留 URL 参数执行 Javascript 重定向 url

cakephp - 使用多个 $this->loadModel ('Model' ) 还是使用数组一个?

javascript - 如何每10秒重定向一个页面?