實現步驟: 1.安裝編譯工具 2.創建運行NGINX的轉有程式 3.下載源碼包並解壓 4.使用configure腳本生成makefile文件 5.編譯安裝 6.創建service文件 說明: 源碼安裝需要提前準備標準的編譯器,GCC的全稱是(GNU Compiler collection),其有GN ...
實現步驟:
-
1.安裝編譯工具
-
2.創建運行NGINX的轉有程式
-
3.下載源碼包並解壓
-
4.使用configure腳本生成makefile文件
-
5.編譯安裝
-
6.創建service文件
說明:
源碼安裝需要提前準備標準的編譯器,GCC的全稱是(GNU Compiler collection),其有GNU開發,並以GPL即LGPL許可,是自由的類UNIX即蘋果電腦Mac OS X操作系統的標準編譯器,因為GCC原本只能處理C語言,所以原名為GNU C語言編譯器,後來得到快速發展,可以處理C++,Fortran,pascal,objectiveC,java以及Ada等其他語言,此外還需要Automake工具,以完成自動創建Makefile的工作,Nginx的一些模塊需要依賴第三方庫,比如: pcre(支持rewrite),zlib(支持gzip模塊)和openssl(支持ssl模塊)等。
範例:CentOS8 編譯安裝nginx1.8
#安裝編譯工具
[root@CentOS8 ~]# yum -y install gcc make pcre-devel openssl-devel zlib-devel
#創建轉有用戶
[root@CentOS8 ~]# useradd -r -s /sbin/nologin nginx
[root@CentOS8 ~]# id nginx
uid=988(nginx) gid=984(nginx) groups=984(nginx)
#下載軟體包
地址:
https://nginx.org/en/download.html
http://nginx.org/download/
#解壓源碼包並編譯
[root@CentOS8 nginx-1.18.0]# mkdir /apps/nginx -p
[root@CentOS8 nginx-1.18.0]# ./configure --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 --prefix=/apps/nginx
[root@CentOS8 nginx-1.18.0]# make -j 4 && make isntall
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ using system zlib library
nginx path prefix: "/apps/nginx"
nginx binary file: "/apps/nginx/sbin/nginx"
nginx modules path: "/apps/nginx/modules"
nginx configuration prefix: "/apps/nginx/conf"
nginx configuration file: "/apps/nginx/conf/nginx.conf"
nginx pid file: "/apps/nginx/logs/nginx.pid"
nginx error log file: "/apps/nginx/logs/error.log"
nginx http access log file: "/apps/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
#創建service文件
[root@CentOS8 conf]# mkdir run
[root@CentOS8 conf]# vim conf/nginx.conf
pid run/nginx.pid;
[root@CentOS8 ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/apps/nginx/run/nginx.pid
ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
LimitNOFILE=100000
[Install]
WantedBy=multi-user.target