使用影像標簽 Nginx:latest 升級 Nginx docker 會導致不執行 PHP 檔案并直接訪問 Web 目錄!
將 docker-compose.yml 從 nginx:1.18.0 升級到 Nginx:latest 似乎會導致一個重大問題。Ngnix 容器不再執行 PHP 檔案并直接訪問 Web 存盤庫的所有內容
- 細節:
docker-compose.yml 的提取物(下面的完整可復制示例)
webserver:
#image: nginx:1.8.0
image: nginx:latest
然后“docker-composer up -d”提出了這個問題。
效果:Nginx 1.18.0 不執行 PHP 檔案(使用 php7.4-fpm)并直接訪問 web 包含 eg: domain.com/index.php 然后可以直接下載!
第一個元素:image nginx:latest 或image nginx 產生相同的效果image nginx:1.8.0(也沒有任何顯式的xyz 標簽)不會產生這個問題
令人不安的事實:帶有標簽的nginx影像:nginx:mainline下載版本#nginx版本:nginx / 1.21.5帶有標簽的nginx影像:nginx:最新下載1.8.0版本#nginx版本:nginx / 1.8.0
可能的問題:影像 nginx:latest 具有以下檔案(提取)
/etc/nginx/nginx.conf
html {
(...)
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*; # THIS LINE IS NEW - instantiated a default site
}
不知道有沒有注意到這一點
帶有“rm /etc/nginx/sites-enabled/”cmd 的 Dockerfile 是可接受的解決方法還是先決條件?
可重現的例子
碼頭工人-compose.yml
version: "3"
services:
cms_php:
image: php:7.4-fpm
container_name: cms_php
restart: unless-stopped
networks:
- internal
- external
volumes:
- ./src:/var/www/html
webserver:
# image: nginx:1.18.0 # OK
# image: nginx:1.17.0 # OK
# image: nginx:mainline # OK
image: nginx:latest # NOK
# image: nginx # NOK
container_name: webserver
depends_on:
- cms_php
restart: unless-stopped
ports:
- 80:80
volumes:
- ./src:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d/
networks:
- external
networks:
external:
driver: bridge
internal:
driver: bridge
nginx-conf/nginx.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
index index.php index.html index.htm;
root /var/www/html;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(. \.php)(/. )$;
fastcgi_pass cms_php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off; access_log off;
}
location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}
src/index.php
<?php echo "Hi..."; ?>
uj5u.com熱心網友回復:
通過以下設定,我可以獲得所需的資料。我不必更改您的檔案。您的路徑/設定可能有問題。嘗試模仿我的設定。我正在使用 nginx:latest。
$ curl localhost:80
Hi...
在此設定中運行 docker 行程
$ docker-compose ps
Name Command State Ports
-----------------------------------------------------------------------
cms_php docker-php-entrypoint php-fpm Up 9000/tcp
webserver /docker-entrypoint.sh ngin ... Up 0.0.0.0:80->80/tcp
檔案夾結構
$ tree
.
├── docker-compose.yaml
├── nginx-conf
│ └── nginx.conf
└── src
└── index.php
2 directories, 3 files
src/index.php
$ cat src/index.php
<?php echo "Hi..."; ?>
docker-compose.yaml
$ cat docker-compose.yaml
version: "3"
services:
cms_php:
image: php:7.4-fpm
container_name: cms_php
restart: unless-stopped
networks:
- internal
- external
volumes:
- ./src:/var/www/html
webserver:
image: nginx:latest
container_name: webserver
depends_on:
- cms_php
restart: unless-stopped
ports:
- 80:80
volumes:
- ./src:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d/
networks:
- external
networks:
external:
driver: bridge
internal:
driver: bridge
nginx-conf/nginx.conf
$ cat nginx-conf/nginx.conf
server {
listen 80;
listen [::]:80;
server_name localhost;
index index.php index.html index.htm;
root /var/www/html;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(. \.php)(/. )$;
fastcgi_pass cms_php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off; access_log off;
}
location = /robots.txt {
log_not_found off; access_log off; allow all;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/415760.html
標籤:
下一篇:所有實體都在私有子網中啟動
