我正在尝试在 docker 容器中使用 nginx。我创建了一个配置文件,它适用于 /,但不适用于 /team/soccer(我需要这个)。在这种情况下,它会转到包含 docker 机器的服务器上的站点。我遗漏了什么吗?myserver 是包含我需要打开的站点的 docker 容器的名称。docker_nginx 是包含 nginx 的 docker 的名称。所有 docker 机器都在 docker 网络内。接下来是 nginx.conf 文件:
events {
worker_connections 1024; # increase if you have lots of clients
accept_mutex off; # "on" if nginx worker_processes > 1
# use epoll; # enable for Linux 2.6+
# use kqueue; # enable for FreeBSD, OSX
}
http {
# proxy_buffering off; <- don't forget to comment out or remove this line.
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
# proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=one:1000m;
proxy_cache_methods GET HEAD;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_valid 200 10m;
# Do gzip compression with nginx, not the play application
gzip on;
gzip_comp_level 9;
gzip_proxied any;
# This is important if you use Play chunked response as chunked response is only available with HTTP 1.1
proxy_http_version 1.1;
upstream mybackend {
server myserver:9000;
}
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;
keepalive_timeout 65;
index index.html index.htm;
server {
listen docker_nginx:80;
#server_name docker_nginx;
location / {
proxy_buffering off;
proxy_pass http://mybackend;
}
location /team/soccer {
proxy_buffering off;
proxy_pass http://mybackend;
}
# location ~ ^/(assets|webjars)/ {
# # proxy_cache one;
# proxy_cache_key "$host$request_uri";
# proxy_cache_valid 200 30d;
# proxy_cache_valid 301 302 10m;
# proxy_cache_valid 404 1m;
# proxy_pass http://backend;
# }
}
}