spell 发表于 2018-1-2 23:31:03

使用Ansible自动配置Nginx服务

#usernobody;  
worker_processes4;
  

  
error_loglogs/error.log;
  
#error_loglogs/error.lognotice;
  
#error_loglogs/error.loginfo;
  

  
pid      logs/nginx.pid;
  

  

  
events {
  worker_connections1024;
  
}
  

  

  
http {
  include       mime.types;
  default_typeapplication/octet-stream;
  

  #log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
  #                  '$status $body_bytes_sent "$http_referer" '
  #                  '"$http_user_agent" "$http_x_forwarded_for"';
  

  
log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"'
  '"$upstream_cache_status"';
  access_loglogs/access.logmain;
  

  sendfile      on;
  #tcp_nopush   on;
  server_tokens off;
  #keepalive_timeout0;
  keepalive_timeout65;
  

  gzipon;
  proxy_connect_timeout      60;
  proxy_read_timeout         30;
  proxy_send_timeout         60;
  proxy_buffer_size          4k;
  proxy_buffers            32 4k;
  proxy_busy_buffers_size    8k;
  proxy_temp_file_write_size 512k;
  proxy_next_upstream http_500 http_502 http_503 error invalid_header;
  

  proxy_temp_path {{ nginx_path }}/proxy_temp;
  proxy_cache_path {{ nginx_path }}/proxy_cache
  levels=1:2 keys_zone=cache_one:100m inactive=2d max_size=2g;
  

  upstream test {
  server 192.168.186.133:8080;
  server 192.168.186.134:8080;
  check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;
  ip_hash;
  
}
  server {
  listen       {{ nginx_port }};
  server_name{{ nginx_host }};
  check_status;
  #charset koi8-r;
  

  #access_loglogs/host.access.logmain;
  location / {
  #   root   html;
  #    indexindex.html index.htm;
  proxy_passhttp://test/baidu/;
  }
  location / {
  proxy_passhttp://test;
  }
  

  
location ~ /purge(/.*) {
  

  #allow 192.168.100.112;
  #allow 192.168.100.64;
  allow all;
  
#deny all;
  proxy_cache_purgecache_one $host$1$is_args$args;
  error_page 405 =200 /purge$1;
  
}
  

  
location ^~ /jenkins {
  

  
proxy_pass http://test/jenkins/;
  

  
proxy_set_header Host $host;
  proxy_set_header   X-Real-IP   $remote_addr;
  proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  

  

  

  
access_log logs/jenkins_access.log main;
  

  
}
  

  

  location /status {
  check_status;
  access_log off;
  #allow 192.168.100.64;
  allow all;
  deny all;
  }
  #error_page404            /404.html;
  
location ~ .*\.(gif|jpg|png|html|css|ico|pdf) {
  proxy_passhttp://test;
  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header   X-Real-IP   $remote_addr;
  proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  

  proxy_cache cache_one;
  add_header Nginx-Cache $upstream_cache_status;
  proxy_cache_valid200 304 301 302 8h;
  proxy_cache_valid 404 1m;
  proxy_cache_validany 2d;
  proxy_cache_key $host$uri$is_args$args;
  expires 30d;
  

  access_loglogs/host.access.logmain;
  
#access_loglogs/access.logmain;
  }
  

  

  

  

  

  

  

  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504/50x.html;
  location = /50x.html {
  root   html;
  }
  

  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  #    proxy_pass   http://127.0.0.1;
  #}
  

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  #location ~ \.php$ {
  #    root         html;
  #    fastcgi_pass   127.0.0.1:9000;
  #    fastcgi_indexindex.php;
  #    fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
  #    include      fastcgi_params;
  #}
  

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  #    denyall;
  #}
  }
  

  

  # another virtual host using mix of IP-, name-, and port-based configuration
  #
  #server {
  #    listen       8000;
  #    listen       somename:8080;
  #    server_namesomenamealiasanother.alias;
  

  #    location / {
  #      root   html;
  #      indexindex.html index.htm;
  #    }
  #}
  

  

  # HTTPS server
  #
  #server {
  #    listen       443 ssl;
  #    server_namelocalhost;
  

  #    ssl_certificate      cert.pem;
  #    ssl_certificate_keycert.key;
  

  #    ssl_session_cache    shared:SSL:1m;
  #    ssl_session_timeout5m;
  

  #    ssl_ciphersHIGH:!aNULL:!MD5;
  #    ssl_prefer_server_cipherson;
  

  #    location / {
  #      root   html;
  #      indexindex.html index.htm;
  #    }
  #}
  

  
}
  
页: [1]
查看完整版本: 使用Ansible自动配置Nginx服务