docker-compose 中的错误在哪里?
Where is the bug in docker-compose?
我运行一个简单的项目(docker-compose和nginx),但它不起作用,我不知道为什么。我包含了项目的全部代码,以免遗漏任何内容。
我的项目包括:
- docker-compose.yaml
- 数据
-
- nginx.conf
- 网站
-
- index.php
docker-compose.yaml:
version: '3.7'
services:
nginx-proxy:
image: nginx:stable-alpine
container_name: nginx-proxy
networks:
- network
ports:
- 80:80
- 443:443
volumes:
- ./data/nginx.conf:/etc/nginx/conf.d/default.conf
website:
image: php:7.4-fpm
container_name: website
volumes:
- ./website:/var/www/html
expose:
- "3000"
networks:
- network
networks:
networks:
driver: bridge
index.php:
<html>
<body>
Body of site
</body>
</html>
nginx.conf:
upstream site {
server website:3000;
}
server {
listen 80;
listen [::]:80;
server_name .test.ru;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name test.ru www.test.ru;
location / {
proxy_pass http://website:3000;
}
}
不知道怎么解决。日志(命令“docker-compose logs nginx-proxy”)仅显示来自客户端的请求。即请求到达,但页面未加载。
但是我需要我的静态页面才能打开。如果 nginx.conf:
我也可以上传项目
server {
return 301 http://google.com;
}
请帮助我。
不幸的是,您不能将 proxy_pass
与 php-fpm
docker 图像一起使用,因为它不提供 http 服务器,但它实现了 fastcgi 协议(如果您需要更多关于 FastCGI Process Manager).
您可以尝试将您的 nginx.conf
替换为:
upstream site {
server website:3000;
}
server {
listen 80;
listen [::]:80;
server_name test.ru;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name test.ru www.test.ru;
root /var/www/html; // You need to define where is your static files directory
location / {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass site; // You can use your upstream here
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
我运行一个简单的项目(docker-compose和nginx),但它不起作用,我不知道为什么。我包含了项目的全部代码,以免遗漏任何内容。
我的项目包括:
- docker-compose.yaml
- 数据
-
- nginx.conf
- 网站
-
- index.php
docker-compose.yaml:
version: '3.7'
services:
nginx-proxy:
image: nginx:stable-alpine
container_name: nginx-proxy
networks:
- network
ports:
- 80:80
- 443:443
volumes:
- ./data/nginx.conf:/etc/nginx/conf.d/default.conf
website:
image: php:7.4-fpm
container_name: website
volumes:
- ./website:/var/www/html
expose:
- "3000"
networks:
- network
networks:
networks:
driver: bridge
index.php:
<html>
<body>
Body of site
</body>
</html>
nginx.conf:
upstream site {
server website:3000;
}
server {
listen 80;
listen [::]:80;
server_name .test.ru;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name test.ru www.test.ru;
location / {
proxy_pass http://website:3000;
}
}
不知道怎么解决。日志(命令“docker-compose logs nginx-proxy”)仅显示来自客户端的请求。即请求到达,但页面未加载。
但是我需要我的静态页面才能打开。如果 nginx.conf:
我也可以上传项目server {
return 301 http://google.com;
}
请帮助我。
不幸的是,您不能将 proxy_pass
与 php-fpm
docker 图像一起使用,因为它不提供 http 服务器,但它实现了 fastcgi 协议(如果您需要更多关于 FastCGI Process Manager).
您可以尝试将您的 nginx.conf
替换为:
upstream site {
server website:3000;
}
server {
listen 80;
listen [::]:80;
server_name test.ru;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name test.ru www.test.ru;
root /var/www/html; // You need to define where is your static files directory
location / {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass site; // You can use your upstream here
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}