我想在nginx后面运行severel服务/页面。每个服务都应通过子目录而不是子域提供。
我使用jwilder / nginx-proxy作为代理容器:
nginx_proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- 80:80
volumes:
- /var/run/docker.sock:/tmp/docker.sock
自有云容器:
web:
image: owncloud:8.1
container_name: my_owncloud
environment:
- VIRTUAL_HOST=www.example.com
ports:
- 8081:80
修改后的nginx配置:
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
default $http_x_forwarded_proto;
'' $scheme;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
default upgrade;
'' close;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log off;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
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 $proxy_x_forwarded_proto;
upstream cloud {
server 172.17.0.3:80:
}
server {
server_name domain.org www.domain.org;
listen 80;
access_log /var/log/nginx/access.log vhost;
index index.html index.htm index.php;
root /var/www/main;
location /cloud/ {
proxy_pass http://cloud/;
}
location / {
proxy_pass http://www.some-domain.com/;
}
location /sub/ {
alias /var/www/sub/;
}
}
问题是owncloud尝试从/而不是/ cloud加载样式,图像等。 Owncloud本身正在运行,可通过domain.org:8081访问。我是否必须添加一些重写,proxy_redirect或其他东西?
答案 0 :(得分:1)
您可以使用' overwritewebroot' as described in the manual。编辑你自己的对话' config / config.php'并包括:
<?php
$CONFIG = array (
...
'overwritewebroot' => '/cloud',
...
);
然后owncloud会考虑&#39; / cloud /&#39;作为任何内部URL的基础(例如,图像,样式等)。