我试图让一个网站的工作,使用php。首先,我试图让它的工作与一个基本的indexiderphp文件。
我没有把端口放在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
以下是我的默认.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>
停靠文件为:
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.
1条答案
按热度按时间svdrlsy41#
我建议做以下几点:
/etc/nginx/conf.d/default.conf
已被您的设置覆盖image: 'nginx:alpine'
,因为您在Dockerfile中有FROM nginx:latest
nginx.conf
中,我总是在位置块中使用/
:location ~ \.php$ {