Score:0

Nginx php-fpm on Docker desktop issue

it flag

I have nginx and php-fpm running in a single container on Docker desktop for Windows. I am IT and not a developer so please dumb it down for me. I have been trying to get a configuration to work without success. I need to be able to allow multiple subdomains to pass through to php-fpm where the php app will determine which database to open by specific sub domain. so clientA.mydomain.com clientB.mydomain.com should all just pass through to php, and the app will know which DB to connect to.

I have searched and found solutions to redirect subdomains to separate sites, but I need to allow all subdomains to single site and process like localhost does.

This work fine using localhost or 127.0.0.1 but when I try to use a dns url the site stops logging in and all ajax calls stop working. Seems like the session variables stop getting passed back. The login page shows, and a failed password will show that error so I know the site is communicating with the proper DB but the log does not show any errors or ajax responses.

server {
    listen       80  default_server;
    server_name  _;  
    # I have tried server_name *.mydomain.com and server_name .mydomain.com, the latter yeilds the same results as this current config.
    
    root /usr/share/nginx/html;
    server_tokens off;

    index index.php index.html index.htm;

    charset utf-8;
    # Add stdout logging
    error_log /dev/stdout info;
    access_log /dev/stdout;

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

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

I had to remove a lot to submit the question.

Using localhost or 127.0.01 with this same config, login works, ajax is responding, and site loads main page as expected.

nginx stdout | 192.168.80.1 - - [08/Sep/2021:13:23:00 +0000] "POST /login.php HTTP/1.1" 302
nginx stdout | 192.168.80.1 - - [08/Sep/2021:13:23:00 +0000] "GET / HTTP/1.1" 200 
nginx stdout | 192.168.80.1 - - [08/Sep/2021:13:23:00 +0000] "GET /framework.js?version=
nginx stdout | 192.168.80.1 - - [08/Sep/2021:13:23:00 +0000] "GET /resources/all.css 
192.168.80.1 - - [08/Sep/2021:13:23:00 +0000] "GET /resources/js/pdfjs/pdf.js 
nginx stdout | 192.168.80.1 - - [08/Sep/2021:13:23:00 +0000] "GET /app.js?version=2021
nginx stdout | 192.168.80.1 - - [08/Sep/2021:13:23:00 +0000] "GET /resources/images/login_loader_logo.gif
192.168.80.1 - - [08/Sep/2021:13:23:01 +0000] "GET /ajax.php?_dc=163110738
192.168.80.1 - - [08/Sep/2021:13:23:02 +0000] "POST /ajax.php HTTP/1.1" 200 
192.168.80.1 - - [08/Sep/2021:13:23:02 +0000] "GET /ajax.php?_dc=1631107382410&

When using the url entry I created in my host file to test it seems like js and ajax are not working using URL.

192.168.96.1 - - [08/Sep/2021:13:29:45 +0000] "GET /login.php HTTP/1.1" 200
192.168.96.1 - - [08/Sep/2021:13:29:45 +0000] "GET /showClientLogo.php HTTP/1.1" 200
192.168.96.1 - - [08/Sep/2021:13:29:46 +0000] "GET / HTTP/1.1" 302
192.168.96.1 - - [08/Sep/2021:13:29:46 +0000] "GET /login.php HTTP/1.1" 200
192.168.96.1 - - [08/Sep/2021:13:29:47 +0000] "GET /showClientLogo.php HTTP/1.1" 200
192.168.96.1 - - [08/Sep/2021:13:29:57 +0000] "POST /login.php HTTP/1.1" 302
192.168.96.1 - - [08/Sep/2021:13:29:57 +0000] "GET / HTTP/1.1" 302
192.168.96.1 - - [08/Sep/2021:13:29:57 +0000] "GET /login.php HTTP/1.1" 200
192.168.96.1 - - [08/Sep/2021:13:29:58 +0000] "GET /showClientLogo.php HTTP/1.1" 200

Thanks in advance.

Michael Hampton avatar
cz flag
Why do you believe this is an nginx issue? It sounds like an issue with the application. Go have a chat with its developer.
WillyK avatar
it flag
Partly because the app and configuration works fine under IIS and php-cgi. I have been installing and configuring this app for years this way. Now we are working to containerize the app and using linux, nginx, and php-fpm. localhost works fine and its just when you introduce a real URL into he mix. This all may work in AWS as is and it may be a docker desktop issue but I'm not sure. Thanks
Score:1
it flag

@MichaelHampton was correct, I tried several things, noticed that new sessions were getting created during redirects which caused the system to keep landing on the login page. There is an internal setting in the app which deals with cross domain cookies and when I turned that off the site works using a domain url. Since I am in testing I am only using http and not https.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.