【问题标题】:How to fix too many redirects yii 1.1.21 with nginx如何使用 nginx 修复太多重定向 yii 1.1.21
【发布时间】:2019-09-30 20:53:31
【问题描述】:

我在 iis 8.5 中有我的 yii 1.1.21 站点,但我需要迁移到 nginx,我是 nginx 的新手,所以我尝试使用本指南:

(https://www.yiiframework.com/doc/guide/1.1/en/quickstart.apache-nginx-config)

在主页上一切正常,但是当我在我的网站中导航时,几乎所有时间都有错误“ERR_TOO_MANY_REDIRECTS”。我尝试了很多解决方案,但没有任何效果。

我在下面发布了我的默认文件以获取更多信息:

server {
    listen 443;
    ssl on;
    ssl_certificate /etc/ssl/certs/key.crt;        # path to your cacert.pem
    ssl_certificate_key /etc/ssl/private/<sermername>.key;    # path to your privkey.pem
    server_name <server name>;
    server_tokens off;
    ssl_prefer_server_ciphers on;
    ssl_protocols TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-R$

    root /var/www/html;
    index index.php

    proxy_pass         http://127.0.0.1:8000;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
    proxy_set_header   X-Forwarded-Proto https;

    proxy_read_timeout  1200s;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header Content-Security-Policy "default-src https: data: 'unsafe-inline' 'unsafe-eval'";
    add_header Referrer-Policy no-referrer;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Frame-Options SAMEORIGIN always;
    add_header X-XSS-Protection "1; mode=block" always;
#   add_header Content-Security-Policy-Report-Only

    access_log /var/log/nginx/default.access.log combined;
    error_log  /var/log/nginx/default.error.log warn;

    set $yii_bootstrap "index.php";
    charset utf-8;

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

    location ~ ^/(protected|framework|themes/\w+/views) {
        deny  all;
    }

    #avoid processing of calls to unexisting static files by yii
     location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
        try_files $uri =404;
    }



    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;

        fastcgi_split_path_info  ^(.+\.php)(.*)$;
        #let yii catch the calls to unexising PHP files
        set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }

#        fastcgi_pass   127.0.0.1:9000;
        include fastcgi_params;
#        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;

        #PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
        fastcgi_param  PATH_INFO        $fastcgi_path_info;

    }

# prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.)
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

}

【问题讨论】:

    标签: php nginx yii yii1.x


    【解决方案1】:

    经过 2 天的努力,我找到了解决方案,我的站点使用负载平衡,而 yii 会话默认情况下无法与多服务器一起使用。 我的解决方案是启用 CDbHttpSession 将会话存储在数据库中。 更多参考: Load balancing with Yii sessions Yii session do not work in multi server

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多