pgporada.httpd
概述:ansible-role-httpd
该角色将设置 httpd(Apache),配置您定义的虚拟主机,并设置任何重写/重定向规则。我按照在数据中心工作时资深管理员教我的方式配置虚拟主机。从那时起,我在职业生涯中一直遵循这种方法。这个设置是有主观性的,您可能不同意。
变量定义
如果您在负载均衡器后面运行 httpd(例如 ELB 或 HaProxy),请使用此选项。如果为真,将把 customer_logger.conf 复制到 /etc/httpd/conf.d/
。客户日志将获得 x-forwarded 源 IP 头。
httpd_is_behind_loadbalancer: false
设置 /etc/httpd/conf/httpd.conf
中的默认文档根目录。对于 Vagrant,通常需要覆盖此设置,否则可以保持不变。
httpd_conf_docrootdir: /var/www/domains
设置 httpd 监听的端口。
httpd_conf_port: 80
httpd_conf_port_ssl: 443
启用或禁用 httpd 的 keepalive 指令。布尔值用于 ansible。文档
httpd_conf_keepalive_enable: true
用于处理请求的多处理模块。文档
httpd_conf_mpm: prefork # 其他有效选项为 'event' 和 'worker'
使用 mod_headers 设置所有 cookie 的 httponly 和 secure。有相关影响。布尔值,默认为 false。文档
httpd_conf_securecookies: false
示例剧本
---
- hosts: localhost
connection: local
become: true
become_method: sudo
vars:
httpd_vhosts_enabled:
- url: jenkins.philporada.com
enable_ssl_vhost: false
#path_to_ssl_ca: /path/to/ca.pem
#path_to_ssl_cert: /path/to/cert.pem
#path_to_ssl_key: /path/to/key.pem
#path_to_ssl_chain: /path/to/bundle.pem
aliases: []
serveradmin: [email protected]
errorlog: "/var/log/httpd/error_log"
accesslog: "/var/log/httpd/access_log"
directory: "/var/www"
docrootdir: public_html
extra_parameters_main: |
#
#RewriteEngine On
# 将来自 ELB 的请求重写为 https
# 我们希望准确匹配 http,而不是负面匹配 !https,因为健康检查在 301 重定向时失败
#RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
extra_parameters_include: |
#
# 这是 Vagrant 特定的
#EnableSendfile Off
# 隐藏与 git 相关的内容
RewriteRule ^(.*/)?\.git+ - [R=404,L]
RewriteRule ^(.*/)?\.gitignore+ - [R=404,L]
roles:
- ansible-roles-httpd
...
如何修改此角色
在运行任何测试之前,您应该使用 yamllint 验证语法。
find . -type f -name "*.yml*" | sed "s|\./||g" | egrep -v "(\.kitchen/|\[warning\]|\.molecule/)" | xargs yamllint -f parsable
您应该看到以下输出,您可以手动处理,或简单忽略。您可以很容易看到我们确实发现了一个错误。这个错误可能会阻止 ansible 完成运行。发现这些错误是好事。
$ find . -type f -name "*.yml*" | sed "s|\./||g" | egrep -v "(\.kitchen/|\[warning\]|\.molecule/)" | xargs yamllint -f parsable
defaults/main.yml:41:121: [warning] 行过长(127 > 120 个字符)(行长度)
meta/main.yml:7:22: [error] 语法错误:不允许在此处映射值
test/integration/default/default.yml:4:1: [warning] 注释未按内容缩进(注释缩进)
test/requirements.yml:2:2: [warning] 注释中缺少起始空格(注释)
您需要一个 Ruby 环境来安装 test-kitchen 的 gem。我们通过 bundler 安装 gem。
git clone git@github.com:pgporada/ansible-role-httpd.git
bundle install
bundle update
bundle exec kitchen create
bundle exec kitchen converge
bundle exec kitchen verify
bundle exec kitchen destroy
现在您应该能够访问 .kitchen.yml
文件定义的 默认页面。
主题音乐
作者信息
GPLv3
Phil Porada