1. 程式人生 > >## **linux伺服器nginx的安裝**

## **linux伺服器nginx的安裝**

系統:Centos7 64位
Nginx: http://nginx.org/en/download.html 目前最新版本1.15.7
nginx

下載模組依賴性Nginx需要依賴下面3個包
1.gzip 模組需要 zlib 庫 ( 下載: http://www.zlib.net/ )
2.rewrite 模組需要 pcre 庫 ( 下載: https://ftp.pcre.org/pub/pcre)
3.ssl 功能需要 openssl 庫 ( 下載: http://www.openssl.org/ )

依賴包安裝順序依次為:openssl、zlib、pcre, 然後安裝Nginx包
wget http://www.openssl.org/source/openssl-fips-2.0.9.tar.gz


wget http://zlib.net/zlib-1.2.11.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre2-10.32.tar.gz或yum -y install pcre-devel
wget http://nginx.org/download/nginx-1.15.7.tar.gz
如果沒有安裝c++編譯環境,還得安裝,通過yum install gcc-c++完成安裝

下一步,編譯安裝
openssl :

[[email protected]] tar zxvf openssl-fips-2.0.9.tar.gz

[[email protected]

] cd openssl-fips-2.0.9

[[email protected] openssl-fips-2.0.9] ./config && make && make install

pcre:

[[email protected]] tar zxvf pcre-2-10.32.tar.gz

[[email protected]] cd pcre-2-10.32

[[email protected] pcre-2-10.32] ./configure && make && make install

zlib:

[[email protected]]tar zxvf zlib-1.2.11.tar.gz

[[email protected]] cd zlib-1.2.11

[[email protected] zlib-1.2.11] ./configure && make && make install

最後安裝nginx

[[email protected]]tar zxvf nginx-1.15.7.tar.gz

[[email protected]] cd nginx-1.15.7

[[email protected] nginx-1.15.7] ./configure && make && make install

安裝完成後,可啟動nginx:
[[email protected] ~]# whereis nginx
nginx: /usr/local/nginx
[[email protected] ~]# cd /usr/local/nginx
[[email protected] nginx]# ll
總用量 4
drwxr-xr-x. 2 root root 4096 12月 2 11:08 conf
drwxr-xr-x. 2 root root 40 12月 2 11:08 html
drwxr-xr-x. 2 root root 6 12月 2 11:08 logs
drwxr-xr-x. 2 root root 19 12月 2 11:08 sbin
[[email protected] nginx]# sbin/nginx

檢視是否已啟動:
[[email protected] nginx]# ps -aux|grep nginx
root 37362 0.0 0.0 20552 616 ? Ss 11:09 0:00 nginx: master process sbin/nginx
nobody 37364 0.0 0.1 23088 1392 ? S 11:09 0:00 nginx: worker process
root 37398 0.0 0.0 112720 984 pts/2 S+ 11:10 0:00 grep --color=auto nginx

通過瀏覽器訪問:
在這裡插入圖片描述
成功!!

到這個就說明nginx安裝並啟動成功。

啟動:/usr/local/nginx/sbin/nginx
停止/重新載入:/usr/local/nginx/sbin/nginx -s stop(quit、reload)
驗證配置檔案是否合法:/usr/local/nginx/sbin/nginx -t
命令幫助:/usr/local/nginx/sbin/nginx -h

小弟第一次寫部落格,有不足之處請指出,謝謝!