我運行了一個簡單的專案(docker-compose 和 nginx),但它不起作用,我不知道為什么。我包括了專案的整個代碼,以免遺漏任何內容。
我的專案包括:
- docker-compose.yaml
- 資料
-
- nginx.conf
- 網站
-
- 索引.php
碼頭工人-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
索引.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;
}
請幫我。
uj5u.com熱心網友回復:
不幸的是,您不能使用proxy_passdockerphp-fpm映像,因為它不提供 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;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/474903.html
上一篇:LEFTJOIN只回傳第一行
