CentOS6.9編譯安裝Nginx1.12


1:安裝必要的庫

Bash
yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel

 

2:創建Nginx用戶和組

Bash
groupadd www #創建一個用戶,不允許登陸和不創主目錄 useradd -s /sbin/nologin -g www -M www

 

3:下載並解壓Nginx

Bash
wget http://nginx.org/download/nginx-1.12.0.tar.gz tar -xzvf nginx-1.12.0 cd nginx-1.12.0

 

4:配置並編譯安裝

Bash
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module make && make install

參數說明:

nginx大部分常用模塊,編譯時./configure --help以--without開頭的都默認安裝。

--prefix=PATH : 指定nginx的安裝目錄。默認 /usr/local/nginx

--conf-path=PATH : 設置nginx.conf配置文件的路徑。nginx允許使用不同的配置文件啟動,通過命令行中的-c選項。默認為prefix/conf/nginx.conf

--user=name: 設置nginx工作進程的用戶。安裝完成后,可以隨時在nginx.conf配置文件更改user指令。默認的用戶名是nobody。--group=name類似

--with-pcre : 設置PCRE庫的源碼路徑,如果已通過yum方式安裝,使用--with-pcre自動找到庫文件。使用--with-pcre=PATH時,需要從PCRE網站下載pcre庫的源碼(版本4.4 - 8.30)並解壓,剩下的就交給Nginx的./configure和make來完成。perl正則表達式使用在location指令和 ngx_http_rewrite_module模塊中。

--with-zlib=PATH : 指定 zlib(版本1.1.3 - 1.2.5)的源碼解壓目錄。在默認就啟用的網絡傳輸壓縮模塊ngx_http_gzip_module時需要使用zlib 。

--with-http_ssl_module : 使用https協議模塊。默認情況下,該模塊沒有被構建。前提是openssl與openssl-devel已安裝

--with-http_stub_status_module : 用來監控 Nginx 的當前狀態

--with-http_realip_module : 通過這個模塊允許我們改變客戶端請求頭中客戶端IP地址值(例如X-Real-IP 或 X-Forwarded-For),意義在於能夠使得后台服務器記錄原始客戶端的IP地址

--add-module=PATH : 添加第三方外部模塊,如nginx-sticky-module-ng或緩存模塊。每次添加新的模塊都要重新編譯(Tengine可以在新加入module時無需重新編譯)

 

5:配置Nginx命令和服務並開機啟動

Bash
vim /etc/init.d/nginx

復制一下代碼到上面的文件

Bash
#!/bin/bash # nginx Startup script for the Nginx HTTP Server # # chkconfig: - 85 15 # description: Nginx is a high-performance web and proxy server. # It has a lot of features, but it's not for everyone. # processname: nginx # pidfile: /var/run/nginx.pid # config: /usr/local/nginx/conf/nginx.conf nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/usr/local/nginx/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " $nginxd -s reload #if your nginx version is below 0.8, please use this command: "kill -HUP `cat ${nginx_pid}`" RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL
Bash
cd /etc/rc.d/init.d #附加執行權限 chmod 755 /etc/init.d/nginx #開機自啟 chkconfig --level 345 nginx on service nginx start #可選 start | stop | restart | reload | status | help


6.查看系統IP地址,打開nginx的本地網頁

[root@bogon ~]# ifconfig eth0 eth0 Link encap:Ethernet HWaddr 00:0C:29:9C:2B:A5 inet addr:192.168.16.87 Bcast:192.168.16.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe9c:2ba5/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1648500 errors:0 dropped:0 overruns:0 frame:0 TX packets:2193 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1606718906 (1.4 GiB) TX bytes:176876 (172.7 KiB)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM