国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

nginx編譯安裝及常用參數詳解

瀏覽:192日期:2023-03-13 15:37:47
目錄
  • 1 基于ansible role實現編譯安裝nginx
  • 2 編譯安裝參數詳解

1 基于ansible role實現編譯安裝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

然后創建nginx項目目錄實現基于role的部署任務

#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      #創建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中調用角色[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 編譯安裝參數詳解

編譯安裝參數示例:

./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

在編譯安裝參數中--with開頭的選項默認是禁用的,想要使用的話就需要在編譯的時候加上;without開頭的選項默認是開啟的,不想要啟用此模塊的話就需要在編譯的時候加上。

通用配置選項參數:

選項解釋說明--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 模塊,該模塊設置適用于客戶端標識的 cookie--without-http_access_module禁用 ngx_http_access_module 模塊,該模塊允許限制對某些客戶端地址的訪問--without-http_rewrite_module禁用 URL 轉發(rewrite)--without-http_proxy_module禁用 HTTP 服務器代理(proxy)模塊--without-http-cache禁用 HTTP 緩存

默認未開啟模塊

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

perl模塊相關選項參數

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

郵件模塊相關配置選項參數

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

stream模塊相關參數

選項解釋說明--with-stream開啟stream模塊--with-stream_ssl_module啟用 stream 模塊的 SSL/TLS 協議支持。構建和運行此模塊需要 OpenSSL 庫。默認情況下未構建此模塊--with-stream_realip_module啟用 ngx_stream_realip_module 模塊的功能,該模塊將客戶端地址更改為 PROXY 協議標頭中發送的地址。默認情況下未構建此模塊--without-stream_access_module禁用 ngx_stream_access_module 模塊,該模塊允許限制對某些客戶端地址的訪問
標簽: Nginx
主站蜘蛛池模板: 欧美日韩精品一区二区三区 | 色九九视频 | 国产视频综合 | 欧美一级毛片日韩一级 | 在线观看国产精成人品 | 成人在免费视频手机观看网站 | 五月久久噜噜噜色影 | 久久精品久久精品久久精品 | 欧美日韩一区二区三区免费 | 国产精品久久久久影院色老大 | 日韩加勒比在线 | a级成人高清毛片 | 爱视频福利广场 | 国产精选在线视频 | 欧美激情综合亚洲一二区 | 欧美一级在线免费观看 | 久久99亚洲精品久久久久网站 | 国产日韩在线视频 | 亚洲欧洲一区二区三区在线 | 国产一级视频在线 | 深夜福利成人 | 999国产精品亚洲77777 | 国产99网站 | 国产精品成人不卡在线观看 | 在线视频免费国产成人 | avtom影院入口永久在线 | 日本韩国欧美在线 | 亚洲国产一区二区三区四区 | 黄色毛片视频在线观看 | 成人高清在线观看播放 | 国产精品久久在线观看 | 免费观看黄色毛片 | 成人小视频在线观看 | 久久精品综合免费观看 | 久久国产三级 | 9cao在线精品免费 | 亚洲天堂网在线播放 | 日本 片 成人 在线 日本68xxxxxxxxx老师 | 99久久久精品免费观看国产 | 一级毛片免费在线观看网站 | 台湾黄三级高清在线观看播放 |