docker-compose中的bug在哪里?



我运行一个简单的项目(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_passphp-fpmdocker镜像,因为它不提供http服务器,但它实现了fastcgi协议代替(如果你需要更多关于fastcgi进程管理器)。

您可以尝试替换您的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;
}
}

最新更新