我試圖運行 NGINX PHP-FPM 應用程式,但我在這里和那里卡住了。
我在 StackOverFlow 上關注了這個主要問題:問題 瀏覽了所有評論,進行了很多更改,但都沒有奏效......
每次我打開 PHP 檔案時,我的瀏覽器都會下載它,而不是在 PHP FPM 上運行腳本。
我所做的步驟如下:
# Create Network
docker network create nginx-php
docker network ls
# Run NGINX and PHP-FPM.
docker run -d -p 9000:9000 --name php-fpm `
--network=nginx-php `
-v D:\Docker\Html:/usr/share/nginx/html php:7.4-fpm-alpine
docker run --name nginx -p 80:80 `
--network=nginx-php `
-v D:\Docker\Html:/usr/share/nginx/html `
-v D:\Docker\Config\nginx:/etc/nginx `
-d nginx:1.23.1-alpine
我的 NGINX 組態檔:
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
root /usr/share/nginx/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass php-fpm:9000; # Nome do container PHP-FPM e onde ele ta hospedado
fastcgi_index index.php;
include fastcgi_params; # Adaptado para Docker
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
} # End of PHP FPM Nginx config example
}
如您所見,帶有 PHP-FPM Pass 的塊與問題和檔案中所述的塊完全相同。
所以我真的不知道發生了什么,有人可以幫助我嗎?
PS:為了清楚起見,您可能想知道為什么不采用 Docker Compose / DockerFile 方法,但我正在采用這種方法,因為我目前正在研究 docker 并且不知道 Docker Compose / DockerFile 是如何作業的,所以我堅持使用基礎知識目前。
編輯:我發現問題只發生在使用 TCP 連接到容器的 fastcgi_pass 上。如果我從 PHP-FPM 復制 /run/php/ 并將其作為卷安裝在兩個容器上,并使用 unix:/run/php/php7.4-fpm.sock 而不是 php-fpm:9000 它可以作業... ._. 是的,但我仍然想使用 TCP 方法,因為它可以更快地部署在任何計算機上。
uj5u.com熱心網友回復:
出于某種原因,在 conf.d 中使用 default.conf 中的“服務器塊”而不是留在 HTTP 塊中解決了問題......
真的不知道為什么,我只是對其進行了測驗,看看它是否可以正常作業。
所以,nginx.conf 保持不變(等于原來的......沒有服務器塊)并且 Default.conf 保持這樣:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /usr/share/nginx/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass php-fpm:9000; # Nome do container PHP-FPM e onde ele ta hospedado
fastcgi_index index.php;
include fastcgi_params; # Adaptado para Docker
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
} # End of PHP FPM Nginx config example
去圖???♂?
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/508688.html
標籤:php码头工人nginx
