我正在嘗試讓一個使用 php 的網站正常作業。首先,我試圖讓它與一個基本的 index.php 檔案一起作業。
我沒有將埠放在 nginx 部分,因為 traefik auto 通過它的反向代理功能來處理這個問題。我有其他網站(博客)在運行它只是有一個帶有 php 網站的 nginx,這似乎給我帶來了問題。
version: '3'
services:
example-website:
container_name: example-website
build: ./Dockerfile
image: 'nginx:alpine'
restart: unless-stopped
links:
- php
networks:
- proxy
- default
labels:
- "traefik.enable=true"
- "traefik.docker.network=proxy"
- "traefik.http.routers.example-secure.entrypoints=websecure"
- "traefik.http.routers.example-secure.rule=Host(`example.com`)"
volumes:
- /var/docker/test/html:/var/www/html
php:
image: php:7.1.11-fpm-alpine
expose:
- 9000
volumes:
- /var/docker/test/html:/var/www/html
networks:
- proxy
- default
networks:
proxy:
external: true
這是我的 default.conf 檔案:
server {
listen 80;
root /var/www/html;
index index.html index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/error.log error;
sendfile off;
client_max_body_size 100m;
location ~ .php$ {
fastcgi_split_path_info ^(. .php)(/. )$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /.ht {
deny all;
}
}
這是 index.php
<!DOCTYPE html>
<head>
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<p><?php echo 'We are running PHP, version: ' . phpversion(); ?></p>
</body>
Dockerfile 是:
FROM nginx:latest
COPY ./conf.d/default.conf /etc/nginx/conf.d/default.conf
目前部署時我只看到:
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
uj5u.com熱心網友回復:
我建議執行以下操作:
- 檢查容器日志是否有任何錯誤
- 登錄到容器以驗證一切都按照您期望的方式設定,例如確保
/etc/nginx/conf.d/default.conf被您的覆寫 - 檢查每個容器中的 nginx 和 php 日志
- 你不需要
image: 'nginx:alpine'在 docker-compose 檔案中,因為你FROM nginx:latest在 Dockerfile 中 - 在 docker-composer 的 nginx 部分中包含一個埠部分以明確
- 在
nginx.conf我總是/在 location 塊中使用 a :location ~ \.php$ {
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/521717.html
