centos7編譯安裝nginx:html
首先確保系統上存在編譯安裝使用的必要工具運行:nginx
# yum groupinstall "development tools" "server platform development"
1 下載PCRE version 4.4 — 8.40 (ngx_http_rewrite_module模塊須要) git
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
2 下載zlib ( ngx_http_gzip_module模塊須要)github
# wget https://zlib.net/zlib-1.2.11.tar.gz
3 下載openssl (http_ssl_module模須要)vim
# wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_0f.tar.gz
3 下載nginx centos
# wget https://nginx.org/download/nginx-1.12.1.tar.gz
正式開工:bash
1 解壓PCREide
# tar xzvf pcre-8.40.tar.gz -C /usr/local/src/
2 解壓zlib 工具
# tar xzf zlib-1.2.11.tar.gz -C /usr/local/src/
3 解壓opensslcentos7
# tar xzf OpenSSL_1_1_0f.tar.gz -C /usr/local/src/
4 安裝nginx
添加nginx用戶:
# groupadd nginx # useradd -g nginx -s /sbin/nologin nginx
建立nginx日誌保存目錄
# mkdir /var/log/nginx
解壓安裝包
# tar xzf nginx-1.12.1.tar.gz # cd nginx-1.12.1 # ./configure --prefix=/usr/local/nginx \ --conf-path=/etc/nginx/nginx.conf \ --pid-path=/var/log/nginx/run/nginx.pid \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --user=nginx --group=nginx \ --with-select_module \ --with-poll_module \ --with-http_ssl_module \ --with-pcre=/usr/local/src/pcre-8.40 \ --with-zlib=/usr/local/src/zlib-1.2.11 \ --with-openssl=/usr/local/src/openssl-OpenSSL_1_1_0f # make && make install
此時,nginx已經安裝完成,能夠去/usr/local/nginx/sbin/下,經過運行 ./nginx 命令來啓動nginx
5 配置NGINX systemd service (注意:根據本身配置,配置路徑信息!)
#vim /lib/systemd/system/nginx.service [Unit] Description=The NGINX HTTP and reverse proxy server After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/var/log/nginx/run/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target
此時
啓動nginx
#systemctl start nginx
查看狀態
# systemctl status nginx
中止nginx
# systemctl stop nginx
6 編譯安裝的nginx不會作日誌分割
#vim logrotate.sh #!/bin/bash cd /var/log/nginx mv access.log access.log.$(date +%F) mv error.log error.log.$(date +%F) kill -USR1 $(cat /var/log/nginx/run/nginx.pid) sleep 1 gzip access.log.$(date +%F) gzip error.log.$(date +%F)
經過crontab實現定時日誌輪替。
若以上內容,有什麼問題,請指正。
謝謝!
參考連接 https://nginx.org/en/docs/configure.html