我正在运行nginx作为前端反向代理,在一个码头(群,单节点)容器中,在Restheart应用程序前面,交付restheart REST服务。
我使用的是最新的登机口图像,用于阿尔卑斯山的ngninx。配置文件附在下面。
作为后端,我使用的是标准的mvn构建的Restheart uberJar,其中大多数情况下只有REST资源访问的根被移动到/api而不是/。当直接访问时,这是完美的。
当我在(打开调试) 8080端口上测试上游服务器( Restheart )时,所有REST都可以正常工作。
我使用httpie进行测试。
当我使用相同的请求在端口8081上通过nginx时,/api/.和/_logic路径..。被捕获并按预期工作。
出于一个我无法理解的原因,/_authtokens/.和/browser/ path不是传递给上游Restheart服务器,而是被第一个块捕获,试图在本地文件系统中定位一个名为/usr/share/nginx/html/.
真正困扰我的是,我不明白为什么它在前两条路上工作得很好,而在另外两条路上却不起作用?
对于在哪里寻找或寻找什么线索或指示,我们将不胜感激。(已经谷歌我的头发几天了.)
泽维尔
# Configuration file for the nginx front-end container.
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
sendfile off;
keepalive_timeout 65;
gzip on;
include /etc/nginx/mime.types;
# default_type application/json;
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 stdout main;
error_log stderr debug;
upstream docker-restheart {
server myrestheart:8080;
}
server {
listen 8081 ;
proxy_pass_request_headers on;
proxy_pass_request_body on;
proxy_http_version 1.1;
proxy_redirect default;
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-Host $server_name;
# Default will serve the index as a test.
# This is also where non allocated locations will end up,
# because it is the first block ..
location / {
root /usr/share/nginx/html/;
}
# Restheart api - ok
location /api/ {
proxy_pass http://docker-restheart;
}
# Restheart _logic - ok
location /_logic/ {
proxy_pass http://docker-restheart;
}
# Restheart _authtokens - does not work ?
location /_authtokens/ {
proxy_pass http://docker-restheart;
}
# Restheart browser - does not work ?
location /browser/ {
proxy_pass http://docker-restheart;
}
# Restheart _authtokens - does not work ?
# Restheart browser - does not work ?
# In both cases, no transfer to upstream happening,
# but instead, caught by the first block ...
}
}# This compose file defines the docker stack for swarm deployement
#
version: "3"
networks:
myoverlay:
driver: overlay
volumes:
dbdata:
services:
mymongo:
image: "mvertes/alpine-mongo:latest"
command: ["mongod","--quiet"]
ports:
- 27017:27017
deploy:
replicas: 1
volumes:
- dbdata:/data/db/
networks:
- myoverlay
myrestheart:
image: openjdk:8-jre-alpine
volumes:
- ./target/MyRestheart-1.0-SNAPSHOT.jar:/myjar.jar:ro
ports:
- 8080:8080
command: ["java","-Dmongo=mongodb://mymongo:27017", "-jar", "/myjar.jar"]
deploy:
replicas: 1
networks:
- myoverlay
mynginx:
image: nginx:alpine
ports:
- 8081:8081
volumes:
- ./nginx.conf:/nginx.conf
command: ["nginx", "-g","daemon off;","-c","/nginx.conf"]
deploy:
replicas: 1
networks:
- myoverlay发布于 2017-11-08 09:12:02
过去,我们在Nginx配置方面也经历过类似的问题。在我们的例子中,我们转移到了对位置的regex语法,它可以工作。类似于:
location ~ /(api|browser|_logic|ping|_authtokens) {
proxy_pass http://docker-restheart;
}发布于 2017-11-08 07:53:29
尝试删除或移动nginx文件中的location /条目。
https://stackoverflow.com/questions/47156444
复制相似问题