【发布时间】:2020-07-28 04:37:28
【问题描述】:
所以我有一个我一直在试验的树莓派网络服务器,它运行 nginx 来服务多个站点等。我想在 docker 容器中作为博客运行 wordpress,但我在正确配置 nginx+docker wordpress 设置时遇到问题。
这是我的 docker-compose.yml:
version: "3"
services:
db:
image: hypriot/rpi-mysql
restart: always
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: <password>
networks:
- wp
wordpress:
depends_on:
- db
image: wordpress
restart: always
volumes:
- ./:/var/www/html/wp-content
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: <password>
ports:
- 8082:80
networks:
- wp
networks:
wp:
volumes:
db_data:
这是我当前的 nginx .conf for example.com:
server {
client_max_body_size 32M;
# Listen HTTP
listen 80;
server_name www.example.com example.com;
# Redirect HTTP to HTTPS
return 301 https://$host$request_uri;
}
server {
client_max_body_size 32M;
# Listen HTTP
listen 443 ssl;
server_name example.com www.example.com;
# SSL config
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# does not fix the issue
port_in_redirect off;
# Proxy Config
location / {
# My attempts at fixing the port issue (did not work in any combination)
proxy_bind $host:443;
proxy_redirect off;
port_in_redirect off;
absolute_redirect off;
proxy_set_header Location $host:443;
proxy_set_header Host $http_host:443;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://localhost:8082/;
# an extra try despite my 8082 port not being open
proxy_redirect https://example.com:8082/ https://example.com/;
}
# testing and looking at just the /wp-login.php "works" but without any of the content
location ~ \.php {
proxy_pass http://127.0.0.1:8082;
}
}
我的问题:在访问我的 example.com 域时,我被重定向到 example.com:8082 并且没有获得任何内容,我在试图找出解决它的方法时遇到了很多问题。我也尝试过在端口 80 上使用 http,但这并没有什么不同(除非我在本地网络上,它在本地获取文件)
我在上面的 nginx 设置中缺少一个简单的东西吗?
有没有办法让 docker 在不同的虚拟端口上转发它?
【问题讨论】:
-
nginx容器配置在哪里?
-
我没有在容器中运行 nginx,因为我还托管了其他非 docker 的东西
标签: wordpress docker nginx raspberry-pi webserver