docker-compose.ymlhtml
version: '3'
services:
nginx:
container_name: nginx
image: nginx
restart: always
external_links:
- app
- postgres
networks:
- default
- info
ports:
- 80:80
- 443:443
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- ./nginx/logs:/var/log/nginx
postgres:
restart: always
container_name: postgres
image: postgres
networks:
- default
- info
ports:
- "5432:5432"
environment:
POSTGRES_DB: info_data
POSTGRES_USER: postgresuser
POSTGRES_PASSWORD: sonic333
PGDATA: /var/lib/postgresql/data/pgdata
volumes:
- ./PG_DATA:/var/lib/postgresql/data/pgdata
app:
restart: always
container_name: infomation
image: 127.0.0.1/hlt/information:test
networks:
- default
- info
volumes:
- ./logs:/tmp/data/info/logl
ports:
- "8200:8080"
external_links:
- postgres
networks:
info:
external: true
複製代碼
app.confnginx
server {
listen 80;
charset utf-8;
access_log off;
location / {
proxy_pass http://$host:8200;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
複製代碼
nginx.confsql
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
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;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
複製代碼
這裏出現的問題:docker
一、出如今同一個宿主機器上,nginx上代理http://$host:8200的時候出現了api
[error] 6#0: *2 connect() failed (111: Connection refused) while connecting to upstream,
client: 172.18.0.1,
server: dev.myproject.com,
request: "GET /api/posts/ HTTP/1.1",
upstream: "http://172.18.0.2:81//posts/, host: "dev.myproject.com", referrer: "http://dev.myproject.com/"複製代碼
的錯誤bash
解決方式:app