我有一个在 Freenas 中运行的 CentOC 虚拟机。我在带有多个容器的虚拟机上安装了 docker。我有 nginx 容器接收本地(端口 80 和 443)和外部流量(端口 443)。我正在尝试为搬运工设置一个虚拟主机,但我只获得了部分成功。这是我的配置:
nginx.conf
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
#error_log /var/log/nginx/debug.log debug;
pid /var/run/nginx.pid;
events {worker_connections 1024;}
http {
upstream backend {server app-server:9000;}
upstream onlyoffice {server onlyoffice-document-server:443;}
## allow cloudflare only ips
include /etc/nginx/myconfig/cloudflare.conf;
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
## proxy mappings
include /etc/nginx/myconfig/proxy.conf;
##
# HTTP host for internal services only
##
server {
listen 0.0.0.0:80;
server_name localhost;
server_tokens off;
## Redirects all traffic to the HTTPS host
root /nowhere; ## root doesn't have to be a valid path since we are redirecting
rewrite ^ https://$host$request_uri? permanent;
}
##
## HTTPS host
##
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name cloud.mydomain.com www.mydomain.com;
server_tokens off;
root /var/www/html;
## block non-cloudflare ips
if ($cloudflare_ip != 1) {return 444;}
## SSL settings
include /etc/nginx/myconfig/ssl.conf;
client_max_body_size 1G; # 0=unlimited - set max upload size
fastcgi_buffers 64 4K;
# Enable gzip but do not remove ETag headers
include /etc/nginx/myconfig/gzip.conf;
index index.php;
error_page 403 /core/templates/403.php;
error_page 404 /core/templates/404.php;
rewrite ^/.well-known/carddav /remote.php/dav/ permanent;
rewrite ^/.well-known/caldav /remote.php/dav/ permanent;
## Locations
###
# For Letsencrypt certificate verification
location ~ /.well-known/acme-challenge {
root /var/www/html/;
allow all;
}
# Locations (nextcloud, calibre, onlyoffice, portainer, etc) on www. and cloud.
include /etc/nginx/myconfig/locations/*.conf;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
}
# virtual hosts
include /etc/nginx/myconfig/vhosts/*.conf;
}
搬运工.conf
server {
listen 80;
server_name portainer.mydomain.com;
location / {
return 301 https://$server_name$request_uri;
}
}
server {
listen 443 ssl;
server_name portainer.mydomain.com;
resolver 127.0.0.11 valid=30s ipv6=off;
set $upstream http://portainer:9000;
ssl_certificate /keys/server.crt;
ssl_certificate_key /keys/server.key;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffers 32 4k;
location / {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass $upstream; #tried this with and without trailing slash
}
location /api/websocket/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_pass $upstream/api/websocket; #tried this with and without trailing slash
}
}
当我导航到 portainer.mydomain.com 时,会打开主身份验证页面,但右上角会显示此错误消息。
Failure
[$resource:badcfg] Error in resource configuration for action `query`. Expected response to contain an array but got an object (Request: GET api/endpoints) http://errors.angularjs.org/1.5.11/$resource/badcfg?p0=query&p1=array&p2=object&p3=GET&p4=api%2Fendpoints
当我输入用户/密码并按登录时没有任何反应。
截图: https ://www.dropbox.com/s/8zneoz21d8zq0au/portainer_image.jpg?dl=0
请注意,通过我的 dockerhost 上暴露的端口 9000 直接连接到 portainer 工作得很好。
请帮我解决这个问题。
2018 年 5 月 12 日更新:问题已解决。事实证明这是 Firefox 缓存内容的问题,因为我正在测试不同的配置。我清除了缓存,现在一切正常:)