【发布时间】:2021-11-21 20:25:20
【问题描述】:
我使用 docker compose 在我的 NAS 上的 docker 容器中运行 Joplin。现在我想设置一个反向代理,以便通过我的个人域访问它。
joplin/docker-compose.yml 文件如下所示:
version: '3'
services:
db:
image: postgres:13.1
volumes:
- /local/joplin:/var/lib/postgresql/data
restart: unless-stopped
environment:
- APP_PORT=22300
- POSTGRES_PASSWORD=********
- POSTGRES_USER=user
- POSTGRES_DB=database
app:
image: joplin/server:2.2.10
depends_on:
- db
ports:
- "22300:22300"
restart: unless-stopped
environment:
- APP_PORT=22300
- APP_BASE_URL=http://192.168.1.2:22300/
- DB_CLIENT=pg
- POSTGRES_PASSWORD=********
- POSTGRES_DATABASE=database
- POSTGRES_USER=user
- POSTGRES_PORT=5432
- POSTGRES_HOST=db
nginx/docker-compose.yml 文件如下所示:
version: '3'
services:
nginx:
image: nginx:latest
ports:
- 8080:80
volumes:
- /local/nginx/nginx.conf:/etc/nginx/nginx.conf
- /local/nginx/sites-enabled:/etc/nginx/sites-enabled
我为我的/local/nginx/nginx.conf 使用了默认值。如下。 :
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
此外,在/local/nginx/sites-enabled/ 文件夹中,我创建了以下文件:
-
/local/nginx/sites-enabled/example.org, -
/local/nginx/sites-enabled/my.example.org。
/local/nginx/sites-enabled/example.org的内容是:
##
# example.org -- Configuration
server {
listen 80;
listen [::]:80;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name example.org;
}
/local/nginx/sites-enabled/my.example.org的内容是:
##
# my.example.org -- Configuration
server {
listen 80;
listen [::]:80;
server_name my.example.org;
location / {
proxy_pass http://192.168.1.2:22300/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Protocol $scheme;
proxy_set_header X-Forwarded-Host $http_host;
}
}
我在路由器上设置了到 nginx 容器的端口转发,它可以工作。 (当我转到http://example.org 时看到 nginx 的 404 屏幕)但是,我很难为 joplin 容器设置反向代理。当我尝试访问 http://my.example.org 时,我收到 510 错误消息。我做错了什么?
奇怪的是,当我将http://192.168.1.2:22300/ 替换为运行测试网页的个人电脑的IP 时,我可以通过http://my.example.org 访问它。即使我在我的电脑上设置了 Joplin,它也可以工作。我的 nginx 或 docker 设置似乎有问题。
【问题讨论】:
标签: docker nginx docker-compose reverse-proxy nginx-reverse-proxy