如何使用Nginx修复太多重定向yii 1.1.21

时间:2019-05-13 21:27:23

标签: php nginx yii

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

}

1 个答案:

答案 0 :(得分:1)

两天后,我发现了解决方案,默认情况下,我的站点可以进行负载平衡,并且yii会话无法在多服务器上正常运行。 我的解决方案是启用CDbHttpSession将会话存储在DB中。 更多参考: Load balancing with Yii sessions Yii session do not work in multi server