我在Freenas内部运行了一个CentOC虚拟机。我在具有多个容器的虚拟机上安装了docker。我有nginx容器接收本地(端口80和443)和外部流量(端口443)。我正在尝试为portainer设置一个虚拟主机,但我只获得了部分成功。这是我的配置:
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;
}
portainer.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时,主auth页面会打开,但右上角会出现此错误消息。
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工作正常。
请帮我解决这个问题。
更新5/12/2018:问题解决了。事实证明,当我测试不同的配置时,Firefox缓存内容存在问题。我清除了缓存,现在一切正常:)