在 Docker 环境下调试主机 NodeJS 应用
wanxger1 分钟阅读
启动 nginx 容器
docker run \
--name test_nginx \
--restart always \
-v /root/test_nginx.conf:/etc/nginx/nginx.conf:ro \
--env "VIRTUAL_HOST=test_nginx.hfbdkj.com" \
--env "LETSENCRYPT_HOST=test_nginx.hfbdkj.com" \
-d \
nginx
nginx 配置文件
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;
server {
listen 80;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-Port $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
location / {
proxy_pass http://172.17.0.1:7001;
}
}
}
注:172.17.0.1 是主机在容器内的 IP 地址。