Nginx Linux詳細安裝部署教程

Nginx簡介

Nginx是一個web服務器也可以用來做負載均衡及反向代理使用,目前使用最多的就是負載均衡,下面介紹安裝步驟

Nginx安裝

1、下載相關組件

[root@localhost src]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
[root@localhost src]# wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
[root@localhost src]# wget http://zlib.net/zlib-1.2.11.tar.gz
[root@localhost src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz

安裝c++編譯環境,如已安裝可略過

[root@localhost src]# yum install gcc-c++
期間會有確認提示輸入y回車
Is this ok [y/N]:y

2、安裝Nginx及相關組件
openssl安裝

[root@localhost src]# tar zxvf openssl-fips-2.0.10.tar.gz
[root@localhost src]# cd openssl-fips-2.0.10
[root@localhost openssl-fips-2.0.10]# ./config && make && make install

pcre安裝

[root@localhost src]# tar zxvf pcre-8.40.tar.gz
[root@localhost src]# cd pcre-8.40
[root@localhost pcre-8.40]# ./configure && make && make install

zlib安裝

[root@localhost src]# tar zxvf zlib-1.2.11.tar.gz
[root@localhost src]# cd zlib-1.2.11
[root@localhost zlib-1.2.11]# ./configure && make && make install

nginx安裝

[root@localhost src]# tar zxvf nginx-1.10.2.tar.gz
[root@localhost src]# cd nginx-1.10.2
[root@localhost nginx-1.10.2]# ./configure && make && make install

3、啓動Nginx
先找一下nginx安裝到什麼位置上了

[root@CentOS6 package]# find / -name nginx
/home/package/nginx-1.10.2/objs/nginx
/usr/local/nginx
/usr/local/nginx/sbin/nginx

執行命令會啓動nginx

/usr/local/nginx/sbin/nginx

報錯了,error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory,按照下面方式解決

1.用whereis libpcre.so.1命令找到libpcre.so.1在哪裏
2.用ln -s /usr/local/lib/libpcre.so.1 /lib64命令做個軟連接就可以了
3.用sbin/nginx啓動Nginx
4.用ps -aux | grep nginx查看狀態

[root@localhost nginx]# whereis libpcre.so.1
[root@localhost nginx]# ln -s /usr/local/lib/libpcre.so.1 /lib64
[root@localhost nginx]# sbin/nginx
[root@localhost nginx]# ps -aux | grep nginx 

進入Linux系統的圖形界面,打開瀏覽器輸入localhost會看到下圖,說明nginx啓動成功
在這裏插入圖片描述
nginx的基本操作

啓動
[root@localhost ~]# /usr/local/nginx/sbin/nginx
停止/重啓
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload)
命令幫助
[root@localhost ~]# /usr/local/nginx/sbin/nginx -h
驗證配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

4、簡單配置Nginx
打開nginx配置文件位於nginx目錄下的conf文件夾下
/usr/local/nginx/conf/nginx.conf

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章