nginx 无法使用 ansible playbook

Tyr_90

我正在使用 ansible 部署 nginx-vts、prometheus、exporter 和 php 一切正常,但 nginx 不断停止和退出......如果我使用 docker compose 运行相同的图像,它们会正常运行。nginx 映像基于 alpine 。

这是我的剧本

- 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;

图像启动但无法正常工作 有什么问题吗?

亚里马丹

您的 nginx 配置中似乎存在语法错误。您应该咨询 docker 日志(例如:docker logs nginx)以查看 nginx 标准输出。它可以帮助显示您在何处出现语法错误。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章