亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

nginx編譯安裝及常用參數(shù)詳解

瀏覽:232日期:2023-03-13 15:37:47
目錄
  • 1 基于ansible role實(shí)現(xiàn)編譯安裝nginx
  • 2 編譯安裝參數(shù)詳解

1 基于ansible role實(shí)現(xiàn)編譯安裝nginx

利用ansible控制端10.0.0.8機(jī)器,在被控制端10.0.0.18上部署nginx

首先打通ansible控制端與被控制端的基于key驗(yàn)證

[root@ansible-rocky ~]$ ssh-copy-id 10.0.0.18[root@ansible-rocky ~]$ ssh 10.0.0.18Last login: Wed Jan 11 12:18:28 2023 from 10.0.0.8[root@rocky8 ~]$ hostname -I10.0.0.18

然后創(chuàng)建nginx項(xiàng)目目錄實(shí)現(xiàn)基于role的部署任務(wù)

#nginx role項(xiàng)目目錄總覽[root@ansible-rocky opt]$ tree /opt/opt├── hosts_nginx├── nginx_role.yml└── roles    └── nginx├── handlers│   └── main.yml├── tasks│   └── main.yml└── templates    ├── nginx.conf.j2    └── nginx.service.j2#task文件[root@ansible-rocky roles]$ cat nginx/tasks/main.yml - name: add group nginx  group: name=nginx system=yes gid=80- name: add user nginx  user: name=nginx group=nginx uid=80 system=yes shell="/sbin/nologin" create_home=no- name: install dependent package  yum: name={{item}} state=latest  loop:    - gcc    - make    - pcre-devel    - openssl-devel    - zlib-devel    - perl-ExtUtils-Embed- name: get nginx source  unarchive:    src: "{{ url }}"    dest: "/usr/local/src"    remote_src: yes- name: compile and install  shell:    cmd: "./configure --prefix={{install_dir}} --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module && make && make install"    chdir: "/usr/local/src/nginx-{{ version }}"    creates: "{{install_dir}}/sbin/nginx"- name: config file  template:    src: nginx.conf.j2    dest: "{{install_dir}}/conf/nginx.conf"    owner: nginx    group: nginx  notify: restart service  tags:    - config- name: create directory  file:    path: "{{install_dir}}/conf/conf.d"    state: directory    owner: nginx    group: nginx- name: change install directory owner  file:    path: "{{install_dir}}"    owner: nginx    group: nginx    recurse: yes- name: copy service file  template:    src: nginx.service.j2    dest: "/lib/systemd/system/nginx.service"- name: check config  shell:    cmd: "{{install_dir}}/sbin/nginx -t"  register: check_nginx_config  changed_when:    - check_nginx_config.stdout.find("successful")    - false- name: start service  systemd:    daemon_reload: yes    name: nginx.service    state: started    enabled: yes      #創(chuàng)建handler文件[root@ansible-rocky roles]$ cat nginx/handlers/main.yml - name: restart service  service:    name: nginx    state: restarted#裝備兩個(gè)template文件[root@ansible-rocky roles]$ cat nginx/templates/nginx.conf.j2 user nginx;worker_processes  {{ ansible_processor_vcpus*2 }};events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    log_format  access_json "{"@timestamp":"$time_iso8601","""host":"$server_addr","""clientip":"$remote_addr","""size":$body_bytes_sent,"""responsetime":$request_time,"""upstreamtime":"$upstream_response_time","""upstreamhost":"$upstream_addr","""http_host":"$host","""uri":"$uri","""xff":"$http_x_forwarded_for","""referer":"$http_referer","""tcp_xff":"$proxy_protocol_addr","""http_user_agent":"$http_user_agent","""status":"$status"}";    # logging          access_log {{install_dir}}/logs/access-json.log access_json;    error_log {{install_dir}}/logs/error.log warn;    keepalive_timeout  65;    include {{install_dir}}/conf/conf.d/*.conf;}[root@ansible-rocky roles]$ cat nginx/templates/nginx.service.j2 [Unit]Description=The nginx HTTP and reverse proxy serverAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile={{install_dir}}/logs/nginx.pidExecStartPre=/bin/rm -f {{install_dir}}/logs/nginx.pidExecStartPre={{install_dir}}/sbin/nginx -tExecStart={{install_dir}}/sbin/nginxExecReload=/bin/kill -s HUP \$MAINPIDKillSignal=SIGQUITTimeoutStopSec=5KillMode=processPrivateTmp=true    LimitNOFILE=100000[Install]WantedBy=multi-user.target#在hosts文件中定義wensrvs需要的變量[root@ansible-rocky opt]$ cat hosts_nginx [websrvs]10.0.0.18[websrvs:vars]version="1.22.1"url="http://nginx.org/download/nginx-{{ version }}.tar.gz"install_dir="/apps/nginx"#在playbook中調(diào)用角色[root@ansible-rocky opt]$ cat nginx_role.yml - hosts: websrvs  remote_user: root  roles:    - nginx    #運(yùn)行playbook[root@ansible-rocky opt]$ ansible-playbook -i hosts_nginx nginx_role.yml PLAY [websrvs] ****************************************************************************************TASK [Gathering Facts] ********************************************************************************ok: [10.0.0.18]TASK [nginx : add group nginx] ************************************************************************changed: [10.0.0.18]TASK [nginx : add user nginx] *************************************************************************changed: [10.0.0.18]TASK [nginx : install dependent package] **************************************************************changed: [10.0.0.18] => (item=gcc)ok: [10.0.0.18] => (item=make)changed: [10.0.0.18] => (item=pcre-devel)changed: [10.0.0.18] => (item=openssl-devel)ok: [10.0.0.18] => (item=zlib-devel)changed: [10.0.0.18] => (item=perl-ExtUtils-Embed)TASK [nginx : get nginx source] ***********************************************************************changed: [10.0.0.18]TASK [nginx : compile and install] ********************************************************************changed: [10.0.0.18]TASK [nginx : config file] ****************************************************************************changed: [10.0.0.18]TASK [nginx : create directory] ***********************************************************************changed: [10.0.0.18]TASK [nginx : change install directory owner] *********************************************************changed: [10.0.0.18]TASK [nginx : copy service file] **********************************************************************changed: [10.0.0.18]TASK [nginx : check config] ***************************************************************************ok: [10.0.0.18]TASK [nginx : start service] **************************************************************************changed: [10.0.0.18]RUNNING HANDLER [nginx : restart service] *************************************************************changed: [10.0.0.18]PLAY RECAP ********************************************************************************************10.0.0.18  : ok=13   changed=11   unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

在被控制端檢查是否安裝完成

2 編譯安裝參數(shù)詳解

編譯安裝參數(shù)示例:

./configure --prefix={{install_dir}} \ --user=nginx \--group=nginx \--with-http_ssl_module \--with-http_v2_module \--with-http_realip_module \--with-http_stub_status_module \--with-http_gzip_static_module \--with-pcre \--with-stream \--with-stream_ssl_module \--with-stream_realip_module

在編譯安裝參數(shù)中--with開(kāi)頭的選項(xiàng)默認(rèn)是禁用的,想要使用的話就需要在編譯的時(shí)候加上;without開(kāi)頭的選項(xiàng)默認(rèn)是開(kāi)啟的,不想要啟用此模塊的話就需要在編譯的時(shí)候加上。

通用配置選項(xiàng)參數(shù):

選項(xiàng)解釋說(shuō)明--prefix=<path>Nginx安裝的根路徑,所有其它路徑都要依賴該選項(xiàng)--sbin-path=<path>指定nginx二進(jìn)制文件的路徑,沒(méi)指定的話 這個(gè)路徑依賴<prefix>選項(xiàng)--conf-path=<path>命令行未指定配置文件,將會(huì)通過(guò)這里指定的路徑加載配置文件--error-log-path=<path>寫(xiě)入錯(cuò)誤日志文件地址,默認(rèn)值:<prefix>/logs/error.log。安裝后,可以使用 nginx.conf 中的 error_log 指令更改。--pid-path=<path>nginx master進(jìn)程pid寫(xiě)入的文件位置,默認(rèn)值:<prefix>/logs/nginx.pid。安裝后,可以使用 nginx.conf 中的 pid 指令更改。--lock-path=<path>共享存儲(chǔ)器互斥鎖文件路徑--user=<user>nginx 運(yùn)行用戶。默認(rèn)值:nobody。安裝后,可以使用 nginx.conf 中的 user 指令更改。--group=<group>nginx 運(yùn)行組。默認(rèn)值:--user 指定的值。安裝后,可以使用 nginx.conf 中的 user 指令更改。

默認(rèn)開(kāi)啟的模塊

選項(xiàng)解釋說(shuō)明--without-http_gzip_module禁用 ngx_http_gzip_module 模塊--without-http_userid_module禁用 ngx_http_userid_module 模塊,該模塊設(shè)置適用于客戶端標(biāo)識(shí)的 cookie--without-http_access_module禁用 ngx_http_access_module 模塊,該模塊允許限制對(duì)某些客戶端地址的訪問(wèn)--without-http_rewrite_module禁用 URL 轉(zhuǎn)發(fā)(rewrite)--without-http_proxy_module禁用 HTTP 服務(wù)器代理(proxy)模塊--without-http-cache禁用 HTTP 緩存

默認(rèn)未開(kāi)啟模塊

選項(xiàng)解釋說(shuō)明--with-http_ssl_module啟用 HTTPS 協(xié)議支持,需要 OpenSSL 庫(kù)。默認(rèn)情況下未構(gòu)建此模塊--with-http_v2_module啟用 HTTP/2 協(xié)議支持。默認(rèn)情況下未構(gòu)建此模塊。--with-http_realip_module啟用 ngx_http_realip_module 模塊的功能,該模塊將客戶端地址更改為在指定的 "header " 字段中發(fā)送的地址。默認(rèn)情況下未構(gòu)建此模塊--with-http_sub_module啟用 ngx_http_sub_module 模塊,該模塊通過(guò)將一個(gè)指定的字符串替換為另一個(gè)指定的字符串來(lái)修改響應(yīng)。默認(rèn)情況下未構(gòu)建此模塊--with-http_gzip_static_module啟用 ngx_http_gzip_static_module 模塊,該模塊支持發(fā)送擴(kuò)展名為 “.gz” 的預(yù)壓縮文件,而不是常規(guī)文件。默認(rèn)情況下未構(gòu)建此模塊--with-http_auth_request_module啟用 ngx_http_auth_request_module 模塊,該模塊基于子請(qǐng)求的結(jié)果實(shí)現(xiàn)客戶端授權(quán)。默認(rèn)情況下未構(gòu)建此模塊--with-http_stub_status_module啟用 ngx_http_stub_status_module 模塊,該模塊提供對(duì)基本狀態(tài)信息的訪問(wèn)。默認(rèn)情況下未構(gòu)建此模塊--add-module=path啟用外部模塊--add-dynamic-module=path啟用外部動(dòng)態(tài)模塊--modules-path=pathnginx 動(dòng)態(tài)模塊的目錄。默認(rèn)值:<prefix>/modules目錄

perl模塊相關(guān)選項(xiàng)參數(shù)

選項(xiàng)解釋說(shuō)明--without-pcre禁用PCRE庫(kù)--with-pcre強(qiáng)制使用PCRE庫(kù)

郵件模塊相關(guān)配置選項(xiàng)參數(shù)

選項(xiàng)解釋說(shuō)明--with-mail激活POP3/IMAP4/SMTP代理模塊,默認(rèn)未激活--with-mail_ssl_module允許ngx_mail_ssl_module模塊這個(gè)模塊使得POP3/IMAP/SMTP可以使用SSL/TLS.配置已經(jīng)定義了HTTP SSL模塊,但是不支持客戶端證書(shū)檢測(cè)--without-mail_pop3_module啟用mail模塊后,單獨(dú)禁用pop3模塊--without-mail_imap_module啟用mail模塊后,單獨(dú)禁用imap模塊--without-mail_smtp_module啟用mail模塊后,單獨(dú)禁用smtp模塊--without-http完全禁用http模塊,如果只想支持mall,可以使用此項(xiàng)設(shè)置--with-openssl=DIR設(shè)定OpenSSL庫(kù)文件路徑

stream模塊相關(guān)參數(shù)

選項(xiàng)解釋說(shuō)明--with-stream開(kāi)啟stream模塊--with-stream_ssl_module啟用 stream 模塊的 SSL/TLS 協(xié)議支持。構(gòu)建和運(yùn)行此模塊需要 OpenSSL 庫(kù)。默認(rèn)情況下未構(gòu)建此模塊--with-stream_realip_module啟用 ngx_stream_realip_module 模塊的功能,該模塊將客戶端地址更改為 PROXY 協(xié)議標(biāo)頭中發(fā)送的地址。默認(rèn)情況下未構(gòu)建此模塊--without-stream_access_module禁用 ngx_stream_access_module 模塊,該模塊允許限制對(duì)某些客戶端地址的訪問(wèn)
標(biāo)簽: Nginx
主站蜘蛛池模板: 麻豆国产精品免费视频 | 欧美午夜艳片欧美精品 | 小黄片毛片 | 一级黄色片黄色片 | 高清免费a级在线观看国产 高清免费毛片 | 成人男女网免费 | 91精品视频网 | 麻豆视频传媒入口 | 欧美一区二区在线视频 | 又黄又爽又猛午夜性色播在线播放 | 欧美vs日韩vs国产在线观看 | 亚洲欧美日韩网站 | 欧美真人毛片动作视频 | 亚洲欧美日韩综合一区久久 | 1级黄色毛片| 成 年 人 黄 片 大全 | 一级二级毛片 | 66av99精品福利视频在线 | 日本特黄特黄刺激大片 | 国产精品麻豆高清在线观看 | 午夜三级黄色片 | 亚洲视频免费在线 | 午夜精品aaa国产福利 | 免费爱爱 | 欧美成人免费毛片 | 亚洲精品一二三 | 精品国产一区二区三区久久影院 | 丁香婷婷亚洲六月综合色 | 人体大胆做受免费视频 | 神马午夜dy888| 麻豆精品在线视频 | 欧美成人午夜不卡在线视频 | 91亚洲精品一区二区自 | 午夜精品在线观看 | 中国美女一级黄色片 | 亚洲国产天堂久久综合 | 欧美三级不卡在线观线看高清 | 久久久一区二区三区不卡 | 国产福利在线免费观看 | 国产一区二区视频在线播放 | 国产自在线 |