欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

ansible配置nginx支持fastcgi

程序员文章站 2022-03-11 08:33:34
...
---
- hosts: 10.0.0.171
  vars:
      nginxver: 1.20.1
      appdir: "/apps/nginx-{{nginxver}}"
      htmldir: /data/nginx/html
  tasks:
    - name: create http conf
      file: path={{appdir}}/conf/http state=directory owner=nginx group=nginx
    - name: create htmldir
      file: path={{htmldir}} state=directory owner=nginx group=nginx 
    - name: exit nginx.conf
      shell: sed -i "/^[[:space:]]*server {/i include {{appdir}}/conf/http/*.conf;" {{appdir}}/conf/nginx.conf 
    - name: create new conf
      copy: 
        content: |
          server {
            listen       80;
            server_name www.huangguanzhou.com;
            root   /data/nginx/html;  
            location / {
                index index.php index.html index.htm;         
            }
            location ~ \.php$ {                        
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include       fastcgi_params;
            }
            location ~ ^/(ping|pm_status)$ {          
                include fastcgi_params;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
            }
          }
        dest: "{{appdir}}/conf/http/test.conf"
    - name: restart nginx
      service: name=nginx state=restarted enabled=yes