Linux centos7環境下Nginx安裝實例分析

1、 首先到nginx官網下載nginx安裝包

下載好后會見到類似下面的一份文件

Linux centos7環境下Nginx安裝實例分析

創建nginx-src目錄并且去到nginx-src目錄里運行如下命令即可:

mkdir?nginx-src?&&?cd?nginx-src

當然也可以在linux底下運行以下命令進行下載nginx安裝包

wget?http://nginx.org/download/nginx-1.5.9.tar.gz

Linux centos7環境下Nginx安裝實例分析

2、解壓nginx-1.5.9.tar.gz文件

tar?-zxvf?nginx-1.5.9.tar.gz

Linux centos7環境下Nginx安裝實例分析

3、刪除安裝包文件命令

rm?-f?nginx-1.5.9.tar.gz

Linux centos7環境下Nginx安裝實例分析

4、配置安裝運行命令

cd?nginx-1.5.9/  ./configure?--prefix=/usr/local/nginx

Linux centos7環境下Nginx安裝實例分析

也許是提示缺包:

./configure: error: the http rewrite module requires the pcre library.

you can either disable the module by using –without-http_rewrite_module

option, or install the pcre library into the system, or build the pcre library

statically from the source with nginx by using –with-pcre= option.

安裝pcre-devel解決問題(需要有網絡下運行并且是超級管理員身份)

yum?-y?install?pcre-devel yum?-y?install?openssl?openssl-devel

Linux centos7環境下Nginx安裝實例分析

要切換為root超級管理員身份: su

Linux centos7環境下Nginx安裝實例分析

Linux centos7環境下Nginx安裝實例分析

現在進行重新配置

./configure –prefix=/usr/local/nginx

如果重新配置也不成功這時需要安裝gcc

yum?–y?install?gcc

Linux centos7環境下Nginx安裝實例分析

安裝好gcc之后再次進行配置

Linux centos7環境下Nginx安裝實例分析

5、編譯命令

make

Linux centos7環境下Nginx安裝實例分析

6、安裝命令

make install

Linux centos7環境下Nginx安裝實例分析

7、安裝完畢,啟動nginx

cd /usr/local/nginx/sbin

./nginx

Linux centos7環境下Nginx安裝實例分析

如果啟動不成功可能是防火墻問題導致

這時需要關閉防火墻

systemctl stop firewalld.service

Linux centos7環境下Nginx安裝實例分析

8、訪問nginx

http://ip地址

Linux centos7環境下Nginx安裝實例分析

9、如果要精簡一下配置文件

重新加載配置文件

運行命令:nginx -s reload

到這里博主我就成功的在linux centos7下安裝了nginx服務器

并且已經成功的在瀏覽器上通過ip地址訪問到nginx。

? 版權聲明
THE END
喜歡就支持一下吧
點贊10 分享