1. 程式人生 > >Nginx安裝部署教程

Nginx安裝部署教程

Nginx簡介

Nginx是一個web伺服器也可以用來做負載均衡及反向代理使用,目前使用最多的就是負載均衡,具體簡介我就不介紹了百度一下有很多,下面直接進入安裝步驟。

Nginx安裝

Linux系統是Centos 6.5 64位,我直接切換到root使用者下安裝,下載相關元件

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

[[email protected] src]# yum install gcc-c++
省略安裝內容…
期間會有確認提示輸入y回車
Is this ok [y/N]:y
省略安裝內容…

安裝Nginx及相關元件

openssl安裝

[[email protected] src]# tar zxvf openssl-fips-2.0.10.tar.gz
省略安裝內容…
[[email protected] src]# cd openssl-fips-2.0.10
[[email protected] openssl-fips-2.0.10]# ./config && make && make install
省略安裝內容…

pcre安裝

[[email protected] src]# tar zxvf pcre-8.40.tar.gz
省略安裝內容…
[

[email protected] src]# cd pcre-8.40
[[email protected] pcre-8.40]# ./configure && make && make install
省略安裝內容…

zlib安裝

[[email protected] src]# tar zxvf nginx-1.10.2.tar.gz
省略安裝內容…
[[email protected] src]# cd nginx-1.10.2
[[email protected] nginx-1.10.2]# ./configure && make && make install
省略安裝內容…

啟動Nginx

先找一下nginx安裝到什麼位置上了,進入nginx目錄並啟動

[[email protected] ~]# whereis nginx
[[email protected] ~]# /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檢視狀態

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

nginx的基本操作

啟動
[[email protected] ~]# /usr/local/nginx/sbin/nginx
停止/重啟
[[email protected] ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload)
命令幫助
[[email protected] ~]# /usr/local/nginx/sbin/nginx -h
驗證配置檔案
[[email protected] ~]# /usr/local/nginx/sbin/nginx -t
配置檔案
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf