【问题标题】:PHP Application redirection cyclePHP 应用程序重定向周期
【发布时间】:2016-04-14 08:27:29
【问题描述】:

我有这个应用程序在标准的 LAMP 堆栈上运行,但是当我尝试在 docker nginx + php-fpm 中运行它时,我得到一个错误(使用richarvey/nginx-php-fpm.docker 容器)。

编辑:这个容器在同一个容器中运行 nginx 和 php-fpm。

http://ip-vm/sistema/index.php/gui/gui/login

server {
    listen   80; ## listen for ipv4; this line is default and implied
    listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    #server_name localhost;

    # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
    sendfile off;

    # Add stdout logging

    error_log /dev/stdout info;
    access_log /dev/stdout;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            index index.php;
            try_files $uri $uri/ /sistemavtr/index.php/$args;
    }

    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/html;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
            fastcgi_split_path_info       ^(.+\.php)(.*)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_read_timeout 120;
    }

    location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
            expires           5d;
    }

    # deny access to . files, for security
    #
    location ~ /\. {
            log_not_found off;
            deny all;
    }

这是标准输出错误:

2016/04/13 23:23:13 [错误] 20#0: *6 重写或内部重定向周期,同时内部重定向到“/sistema/index.php/”,客户端:192.168.139.1,服务器:,请求:“GET /sistema/index.php/gui/gui/login HTTP/1.1”,主机:“192.168.139.132”

192.168.139.1 - - [13/Apr/2016:23:23:13 +0000] "GET /sistema/index.php/gui/gui/login HTTP/1.1" 500 594 "-" "Mozilla/5.0 (Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,如 Gecko)Chrome/49.0.2623.112 Safari/537.36"

所以,我不确定是 PHP Codeigniter App + ExtJS 的问题,还是 URL 模式 (index.php/gui/gui/login) 的问题。

【问题讨论】:

    标签: php codeigniter nginx docker


    【解决方案1】:

    你的 nginx 配置,fastcgi 的一部分

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
            fastcgi_split_path_info       ^(.+\.php)(.*)$;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO       $fastcgi_path_info;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
            fastcgi_index index.php;
            include fastcgi_params;
            fastcgi_read_timeout 120;
    }
    

    您的配置尝试将 php 代理到 unix 套接字,而不是 9000 端口。

    应该是fastcgi_pass unix:/var/run/php5-fpm.sock;改为fastcgi_pass 127.0.0.1:9000

    接下来。试试看 php-fpm 的配置,应该会找到监听端口。

    最后 - 如果您使用的是 docker - 请确保所有 docker 主机都可以相互访问

    UPD 1:似乎.htaccess 也可能有问题 - 可以为特定主机保存 apache 规则,例如 - 重定向。 PHP-FPM 不会读取该文件并忽略它。

    UPD 2.htaccess 可以在 PHP Web 根文件夹(您的 index.php 所在的位置)中找到

    【讨论】:

    • 当前“/etc/php/fpm/pool.d/www.conf”指向“listen = /var/run/php5-fpm.sock”。我应该将其更改为“127.0.0.1:9000”吗? PS:它们在同一个docker容器中,
    • 按照您的建议进行更改会引发以下错误:[error] 19#0: *1 rewrite or internal redirect cycle while internal redirecting to "/sistema/index.php/gui/gui/login/ index.php//index.php//index.php//index.php//index.php//index.php//index.php//index.php//index.php//index.php// index.php/”,客户端:192.168.139.1,服务器:,请求:“GET /sistema/index.php/gui/gui/login HTTP/1.1”,主机:“192.168.139.132”
    • 如果它们在同一个容器中 - unix socket 应该可以工作。您的问题中没有明确说明。
    • 是的,你是对的,我正在编辑问题。谢谢!
    • 在您的问题中,您发布了 URL http://ip-vm/sistema/index.php/gui/gui/login。这是正确的uri吗?我的意思是您的网络服务器应该正确回答 sistema/index.php/gui/gui/login ?还是网址不正确?
    【解决方案2】:

    所以,最终问题出在 default.conf。

    使用这个问题作为指导配置它我终于做到了:Nginx doesn't server subfolder api application (php-fpm)

    所以我的 /etc/nginx/sites-enabled/default.conf 像这样结束:

    server {
        listen   80; ## listen for ipv4; this line is default and implied
        listen   [::]:80 default ipv6only=on; ## listen for ipv6
    
        root /usr/share/nginx/html;
        index index.php index.html index.htm;
    
        # Make site accessible from http://localhost/
        #server_name localhost;
    
        # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
        sendfile off;
    
        # Add stdout logging
    
        error_log /dev/stdout info;
        access_log /dev/stdout;
    
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                index index.php;
                try_files $uri $uri/ /index.php?$query_string;
        }
        location /sistema/ {
                index /server/index.php;
                try_files $uri /server/index.php/$uri;
        }
        #error_page 404 /404.html;
    
        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php {
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                include fastcgi_params;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_read_timeout 120;
        }
    
        location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
                expires           5d;
        }
    
        # deny access to . files, for security
        #
        location ~ /\. {
                log_not_found off;
                deny all;
        }
    

    我不太确定这到底是如何工作的,所以,我是如何让它工作的,但如果有人可以向我解释这一点,我将非常感激。

    【讨论】:

      猜你喜欢
      • 2016-02-21
      • 2017-01-03
      • 2017-09-26
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      • 2017-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多