Nginx
Docker 桌面問題上的 Nginx php-fpm
我在適用於 Windows 的 Docker 桌面上的單個容器中執行 nginx 和 php-fpm。我是 IT 而不是開發人員,所以請幫我把它搞砸。我一直試圖讓配置工作但沒有成功。我需要能夠允許多個子域傳遞到 php-fpm,其中 php 應用程序將確定由特定子域打開哪個數據庫。所以clientA.mydomain.com clientB.mydomain.com 應該都只是通過php,應用程序將知道要連接到哪個數據庫。
我已經搜尋並找到了將子域重定向到單獨站點的解決方案,但我需要允許所有子域到單個站點並像 localhost 一樣處理。
使用 localhost 或 127.0.0.1 可以正常工作,但是當我嘗試使用 dns url 時,站點停止登錄並且所有 ajax 呼叫都停止工作。似乎會話變數停止傳回。登錄頁面顯示,密碼失敗將顯示該錯誤,因此我知道該站點正在與正確的數據庫通信,但日誌未顯示任何錯誤或 ajax 響應。
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; } }
我必須刪除很多內容才能送出問題。
使用具有相同配置的 localhost 或 127.0.01 ,登錄有效,ajax 響應,並且站點按預期載入首頁。
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&
當使用我在主機文件中創建的 url 條目進行測試時,似乎 js 和 ajax 無法使用 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
提前致謝。
@MichaelHampton 是正確的,我嘗試了幾件事,注意到在重定向期間創建了新會話,這導致系統繼續登陸登錄頁面。應用程序中有一個處理跨域 cookie 的內部設置,當我關閉它時,該站點使用域 url 工作。因為我在測試我只使用http而不是https。