简体   繁体   English

nginx无法使用ansible剧本

[英]nginx is not working with ansible playbook

I'm using ansible to deploy nginx-vts , prometheus, exporter and php everything works fine but nginx keeps stopping and exiting .... if i run the same images with docker compose they tun normally . 我正在使用ansible部署nginx-vts,prometheus,exporter和php,但一切正常,但是nginx会不断停止并退出....如果我在docker上运行相同的映像,则它们会正常调整。 the nginx image is based on alpine . nginx图像基于alpine。

this is my playbook 这是我的剧本

- 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

this is my nginx config file 这是我的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;
        }
    }
}

IMPORTANT NOTE : 重要的提示 :

if i delete the line 如果我删除行

        include /etc/nginx/conf.d/*.conf;

the image launches but it does not work correctly is there anything wrong ? 图像启动,但无法正常工作,是否有问题?

It looks like you have a syntax error in your nginx configuration. 看起来您的nginx配置中存在语法错误。 You should consult to docker logs (eg: docker logs nginx) in order to see nginx stdout. 您应该查阅docker日志(例如:docker logs nginx)以查看nginx stdout。 It can help to show where you have syntax errors. 它有助于显示语法错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM