4

I have this application working on a standard LAMP stack, but when i try to run it in a docker nginx + php-fpm i get an error (using richarvey/nginx-php-fpm. docker container).

Edit: This container runs nginx and php-fpm in the same container.

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

And this is the stdout error:

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"

So, im not sure if is the PHP Codeigniter App + ExtJS the problem, or is the URL pattern (index.php/gui/gui/login) what is not working.

Danilo Velasquez
  • 451
  • 2
  • 11

2 Answers2

1

your config of nginx, part for 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;
}

Your config tries to proxy php to unix socket, not to the 9000 port.

Should be fastcgi_pass unix:/var/run/php5-fpm.sock; changed to fastcgi_pass 127.0.0.1:9000

Next. Try to watch php-fpm config, there you should find listening port.

And finally - if you are using docker - be sure, that all docker hosts are accessible from each other

UPD 1: Seems it can be also problem with .htaccess - there are can be saved apache rules for specific host, for example - redirecting. PHP-FPM doesn't read that file and ignore it.

UPD 2: .htaccess can be found in PHP web root folder (where your index.php is located)

Victor Perov
  • 1,697
  • 18
  • 37
  • Currently the "/etc/php/fpm/pool.d/www.conf" is pointing to "listen = /var/run/php5-fpm.sock". Should i change that for "127.0.0.1:9000"? PS: They are in the same docker container, – Danilo Velasquez Apr 14 '16 at 08:49
  • Changing as you suggest throws me the following error: [error] 19#0: *1 rewrite or internal redirection cycle while internally 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/", client: 192.168.139.1, server: , request: "GET /sistema/index.php/gui/gui/login HTTP/1.1", host: "192.168.139.132" – Danilo Velasquez Apr 14 '16 at 08:57
  • If they are in same container - unix socket should be work. It wasn't clearly in your question. – Victor Perov Apr 14 '16 at 08:57
  • Yes, you are right, im editing the question. Thanks! – Danilo Velasquez Apr 14 '16 at 08:59
  • In your question you posted URL `http://ip-vm/sistema/index.php/gui/gui/login` . Is that correct uri? I mean your web-server should correctly answer on `sistema/index.php/gui/gui/login` ? Or it's not correct url? – Victor Perov Apr 14 '16 at 09:01
  • Oh, apache. Have you implemented some apache logic in .htaccess ? – Victor Perov Apr 14 '16 at 09:35
  • As far i can see, i dont find any .htaccess in my apache server in /var/www/html folder. There is some other place i should look? – Danilo Velasquez Apr 14 '16 at 10:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/109187/discussion-between-danilo-velasquez-and-victor-perov). – Danilo Velasquez Apr 14 '16 at 18:17
0

So, finally the problem was the default.conf.

Using this question as guide to configure it i finally made it: Nginx doesn't server subfolder api application (php-fpm)

So my /etc/nginx/sites-enabled/default.conf end like this:

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

Im not very sure how this really works, so, its how i make it work but if anyone can explain this to me, i will be very grateful.

Community
  • 1
  • 1
Danilo Velasquez
  • 451
  • 2
  • 11