我正在使用ansible来部署nginx-vts,prometheus,exporter和php,但一切正常,但是nginx会不断停止并退出....如果我在docker上运行相同的映像,则它们会正常调整。 nginx图像基于高山。
这是我的剧本
- hosts: localhost
connection: local
tasks:
- name: x-vts
docker_container:
name: x-nginx
image: x:latest
state: started
volumes:
- ./php:/var/www/html/x.com
- ./site.conf:/etc/nginx/conf.d/x.com.conf:ro
ports:
- 80:80
- name: php
docker_container:
name: x-php
image: php:fpm
state: started
volumes:
- ./php:/var/www/html/x.com
- name: nginx-vts-exporter
docker_container:
name: x-Exporter
image: sophos/nginx-vts-exporter:latest
state: started
ports:
- 9913:9913
command:
- NGINX_HOST=http://nginx:80
- name: prom
docker_container:
name: x-prometheus
image: prom/prometheus:latest
state: started
ports:
- 9090:9090
volumes:
- ./monitor/prometheus.yml:/etc/prometheus/prometheus.yml
这是我的Nginx配置文件
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
vhost_traffic_status_zone;
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"';
log_format json_combined escape=json '{"time_local":"$time_local", '
'"proxy_addr":"$remote_addr", '
'"remote_addr":"$http_x_forwarded_for", '
'"remote_user":"$remote_user", '
'"request":"$request", '
'"status":"$status", '
'"body_bytes_sent":"$body_bytes_sent", '
'"request_time":"$request_time", '
'"upstream_connect_time":"$upstream_connect_time", '
'"upstream_header_time":"$upstream_header_time", '
'"upstream_response_time":"$upstream_response_time", '
'"http_referrer":"$http_referer", '
'"http_user_agent":"$http_user_agent"}';
access_log /dev/stdout json_combined;
error_log /dev/stderr info;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 11050;
server_name nginx_vts_status
access_log off;
location /status {
vhost_traffic_status_bypass_limit on;
vhost_traffic_status_bypass_stats on;
vhost_traffic_status_display;
vhost_traffic_status_display_format json;
}
}
}
重要提示:
如果我删除该行
include /etc/nginx/conf.d/*.conf;
图像启动但无法正常工作,是否有问题?
答案 0 :(得分:0)
您的nginx配置中似乎有语法错误。您应该查阅docker日志(例如:docker logs nginx)以查看nginx stdout。它可以帮助显示哪里有语法错误。