Linux中Nginx安裝與配置詳解


安裝所需環境

Nginx 是 C語言 開發,建議在 Linux 上運行,當然,也可以安裝 Windows 版本,本篇則使用 CentOS 7 作為安裝環境。

上網配置:

如果安裝了centos 之后無法上網,只需要修改一個小小的配置使用 root用戶,

進入 /etc/sysconfig/network-script/ifcfg-ens33 (可能你的網卡不是這名字,需要找到自己的網卡 在這個文件夾中輸入 ifcfg-e 然后按TAB鍵就可以) 在這個文件中 修改onboot=yes (原來是 no) 然后 重啟機器 命令 reboot now 就可以上網了;

 (1) 登陸linux:

下載nginx:    wget http://nginx.org/download/nginx-1.8.0.tar.gz
下載openssl : wget http://www.openssl.org/source/openssl-fips-2.0.9.tar.gz
下載zlib    : wget http://zlib.net/zlib-1.2.11.tar.gz 
(這里是最新的版本,如果這個地址無法下載,請在瀏覽器中輸入http://zlib.net/ 看看最近的是什么版本,改一下版本號就可以 比如 wget http://zlib.net/zlib-1.2.34.tar.gz)
下載pcre : wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz 
(如果沒有此壓縮包,跟剛才一樣的處理,輸入ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/,看一下最近發布的包,然后改一下 包的版本,再下載即可)
下載perl5  wget http://www.cpan.org/src/5.0/perl-5.16.1.tar.gz

以上安裝包,也可以在單獨下載后,上傳至Centos,然后編譯安裝;

一. gcc 安裝
安裝 nginx 需要先將官網下載的源碼進行編譯,編譯依賴 gcc 環境,如果沒有 gcc 環境,則需要安裝:
通過yum install gcc-c++ -y完成安裝
二.perl安裝

解壓源碼包
[root@akinlau /]# tar -xzf perl-5.16.1.tar.gz

編譯並安裝,目錄可以自定義

[root@akinlau /]# cd perl-5.16.1
[root@akinlau perl-5.16.1]# ./Configure -des -Dprefix=/usr/local/perl

[root@akinlau perl-5.16.1]# make
[root@akinlau perl-5.16.1]# make test
[root@akinlau perl-5.16.1]# make install

如果系統以前已安裝了舊版本的perl的話,替換系統原有的版本。
[root@akinlau perl-5.16.1]# mv /usr/bin/perl /usr/bin/perl.bak
[root@akinlau perl-5.16.1]# ln -s /usr/local/perl/bin/perl /usr/bin/perl

再看看是不是最新的版本

[root@akinlau perl-5.16.1]# perl -v

This is perl 5, version 16, subversion 1 (v5.16.1) built for x86_64-linux

Copyright 1987-2012, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using “man perl” or “perldoc perl”. If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

 

如果看到以上信息,就證明perl安裝成功了

 三、然后開始安裝:openssl : [root@localhost] tar zxvf openssl-fips-2.0.9.tar.gz [root@localhost] cd openssl-fips-2.0.9 [root@localhost] ./config && make && make install
四、安裝pcre:
[root@localhost] tar zxvf pcre-8.36.tar.gz [root@localhost] cd pcre-8.36 [root@localhost] ./configure && make && make install 五、開始安裝:zlib: [root@localhost]tar zxvf zlib-1.2.8.tar.gz [root@localhost] cd zlib-1.2.8 [root@localhost] ./configure && make && make install 六、最后安裝nginx [root@localhost]tar zxvf nginx-1.8.0.tar.gz [root@localhost] cd nginx-1.8.0 [root@localhost] ./configure && make && make install

 (8) 啟動nginx/usr/local/nginx/sbin/nginx


然后測試一下:
使用ps -ef | grep nginx

(9)防火牆關掉

方法: systemctl stop firewalld.service
systemctl disable firewalld.service

然后前台訪問: 使用 http://192.168.111.135(請換成您機器的ip)

(11) 如果想要停止,請使用:

pkill -9 nginx


參考:http://www.centoscn.com/image-text/install/2014/0928/3869.html

安裝perl5:
http://www.centoscn.com/image-text/install/2014/0928/3869.html

啟動nginx

http://www.cnblogs.com/codingcloud/p/5095066.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM