Nginx安裝文檔

0.準備工作

#安裝上傳下載軟件包lrzsz
yum install lrzsz

1.安裝版本

nginx-1.16.0.tar.gz

pcre-8.38.tar.gz(讓Nginx 支持 Rewrite 功能)

2.安裝環境

CentOS

3.安裝依賴

yum -y install make zlib zlib-devel gcc gcc-c++ libtool  openssl openssl-devel

1.編譯需要 gcc 環境,gcc gcc-c++

2.PCRE(Perl Compatible Regular Expressions) 是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式,所以需要在 linux 上安裝 pcre 庫,pcre-devel 是使用 pcre 開發的一個二次開發庫,所以需要:pcre pcre-devel ;#PCRE 作用是讓 Nginx 支持 Rewrite 功能

3、zlib 庫提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip ,所以需要在 Centos 上安裝 zlib 庫,所以需要:zlib zlib-devel ;

4、OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及 SSL 協議,並提供豐富的應用程序供測試或其它目的使用。nginx 不僅支持 http 協議,還支持 https(即在ssl協議上傳輸http),所以需要在 Centos 安裝 OpenSSL 庫,所以需要:openssl openssl-devel ;

tar zxvf pcre-8.38.tar.gz
cd pcre-8.38/
./configure
make && make install

3.安裝配置

非root用戶無法使用1024以下端口,Nginx通常監聽80端口,所以我們使用root用戶安裝nginx。

  • 安裝Nginx
# 上傳nginx安裝包
cd /opt
rz nginx-1.16.0.tar.gz
tar zxvf nginx-1.16.0.tar.gz
cd /opt/nginx-1.16.0
# 配置,指定編譯之後安裝目錄
./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/pcre-8.38
make && make install
# 添加環境變量
vi /etc/profile
unset i
unset -f pathmunge
export JAVA_HOME=/usr/local/jdk1.8.0_144
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin:/opt/nginx/sbin
# 使環境變量生效
source /etc/profile
# 查看nginx版本
nginx -v
# 啓動nginx服務,如果./configure --prefix=/opt/nginx沒有指定安裝目錄,則默認安裝到/usr/local
cd /opt/nginx/sbin/
./nginx
# 驗證服務是否啓動成功
ps aux | grep nginx

Nginx常用命令

# 啓動
./nginx
# 重啓
./nginx -s reload
# 停止
./nginx -s stop
# 強制關閉nginx服務
ps -ef | grep nginx
kill -9 [nginx]
  • 配置Nginx自啓動
# 添加nginx服務
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/opt/nginx/sbin/nginx -s reload
ExecStop=/opt/nginx/sbin/nginx -s stop
# 重載
systemctl daemon-reload
# 以服務的方式啓動nginx
systemctl start nginx
# 配置nginx服務自動啓動
systemctl enable nginx
# 驗證服務是否啓動成功
systemctl status nginx
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章