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

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

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

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

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

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

首先打通ansible控制端與被控制端的基于key驗證

[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àn)基于role的部署任務(wù)

#nginx role項目目錄總覽[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#裝備兩個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    #運行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開頭的選項默認是禁用的,想要使用的話就需要在編譯的時候加上;without開頭的選項默認是開啟的,不想要啟用此模塊的話就需要在編譯的時候加上。

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

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

默認開啟的模塊

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

默認未開啟模塊

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

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

選項解釋說明--without-pcre禁用PCRE庫--with-pcre強制使用PCRE庫

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

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

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

選項解釋說明--with-stream開啟stream模塊--with-stream_ssl_module啟用 stream 模塊的 SSL/TLS 協(xié)議支持。構(gòu)建和運行此模塊需要 OpenSSL 庫。默認情況下未構(gòu)建此模塊--with-stream_realip_module啟用 ngx_stream_realip_module 模塊的功能,該模塊將客戶端地址更改為 PROXY 協(xié)議標頭中發(fā)送的地址。默認情況下未構(gòu)建此模塊--without-stream_access_module禁用 ngx_stream_access_module 模塊,該模塊允許限制對某些客戶端地址的訪問
標簽: Nginx
主站蜘蛛池模板: 亚洲国产成人久久综合一区 | 最新精品视频在线观看 | 国产亚洲综合成人91精品 | 欧美操片在线观看 | 免费观看黄色大片 | 人成免费a级毛片 | 欧美日韩亚洲综合另类ac | 青青草国产三级精品三级 | 国产aaa级一级毛片 国产aaa免费视频国产 | 国产露脸真实作爱视频 | 欧美 日韩 国产 成人 在线观看 | 九月婷婷开心九月 | 婷婷丁香五月中文字幕 | 99久久免费中文字幕精品 | 久久精品94精品久久精品动漫 | 五月色综合婷婷综合俺来也 | 欧美日日操| 国产尤物二区三区在线观看 | 日本高清色本免费现在观看 | 午夜亚洲国产成人不卡在线 | 午夜精品久久久久久久爽 | 精品国产成人高清在线 | 国产91长腿美女在线观看 | 99精品国产美女福到在线不卡 | 国产毛片一区二区三区 | 国产精品伦理一二三区伦理 | 午夜影视水蜜桃网站 | 亚洲欧美日韩专区一 | 一道精品视频一区二区三区图片 | 国产人成午夜免视频网站 | 国产成人福利色视频 | 亚洲欧美日韩中文综合v日本 | 欧美日韩精品一区二区三区视频在线 | 国产jav | 极品主播的慰在线播放 | 亚洲人成一区二区三区 | 91香蕉小视频 | 国产精品揄拍100视频 | 特级a毛片| 亚洲v欧美v日韩v国产v | 好爽快一点视频在线观看 |