我有自由和组合使用自由和nginx容器,但从nginx请求调用得到404错误。我有
示例:Liberty API URL:http://localhost:9082/sxrw-main/api/v1/terminals
nginx URL:http://localhost:81/sxrw-main/api/v1/terminals抛出404错误
泊坞窗,撰写
version: "3"
services:
ship-api:
image: docker.csx.com/websphere-liberty:javaee8
volumes:
- ./dist/config:/config
- ./dist/shared:/opt/ibm/wlp/usr/shared
ports:
- 9082:9080
- 944:9443
ship-web:
image: docker.csx.com/nginx:latest
ports:
- "81:80"
volumes:
- ./html:/usr/share/nginx/html
- ./nginx.conf:/etc/nginx/nginx.conf
links:
- ship-api
networks:
- shipcsx
networks:
shipcsx:
driver: bridge
这是我的nginx.conf文件
events {
worker_connections 1024;
}
http {
server {
listen 80;
location /sxrw-main/api {
proxy_pass http://ship-api:9082;
}
}
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;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
您可能需要将ship-api添加到shipcsx网络。我不认为具有指定网络的容器也会加入默认网络,即使指定了链接,它们也必须共享网络。
“注意:如果你定义了链接和网络,那么它们之间有链接的服务必须共享至少一个共同的网络才能进行通信。我们建议使用网络。”来自documentation