2016-04-14 42 views
3

我有这个应用程序工作在一个标准的LAMP堆栈上,但是当我尝试在docker中运行它nginx + php-fpm我得到一个错误(使用richarvey/nginx-php-fpm。docker container)。PHP应用程序重定向周期

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

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

app error

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 [error] 20#0: *6 rewrite or internal redirection cycle while internally redirecting to "/sistema/index.php/", client: 192.168.139.1, server: , request: "GET /sistema/index.php/gui/gui/login HTTP/1.1", host: "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, like Gecko) Chrome/49.0.2623.112 Safari/537.36"

因此,林不知道,如果是PHP笨应用+ ExtJS的问题,或者是URL模式(index.php/gui/gui/login)有什么不起作用。

回答

0

所以,最后的问题是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; 
    } 

我不是很确定这是如何工作的,因此,我如何让它工作,但如果有人能向我解释这一点,我将非常感激。

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配置,在那里你应该找到监听端口。

最后 - 如果你正在使用泊坞窗 - 可以肯定,所有的码头工人的主机彼此

UPD 1访问:看来,这可能是也问题.htaccess - 有可以保存阿帕奇规则对于特定的主机,例如 - 重定向。 PHP-FPM不会读取该文件并忽略它。

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

+0

目前“/etc/php/fpm/pool.d/www.conf”指向“listen = /var/run/php5-fpm.sock”。我应该改变“127.0.0.1:9000”吗? PS:它们在同一个码头容器中, –

+0

按照您的建议更改会引发以下错误:[error] 19#0:* 1在内部重定向到“/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 /“,client:192.168.139.1,server:,request:”GET /sistema/index.php/gui/gui/login HTTP/1.1“,host:”192.168.139.132“ –

+0

如果它们是在相同的容器 - unix插座应该工作。你的问题并不清楚。 –