Linux下nginx的安装与部署

版权声明:若转载请指明出处 https://blog.csdn.net/qq_24790545/article/details/82594977

安装所需环境
Nginx 是 C语言 开发,建议在 Linux 上运行,本篇则使用 CentOS 7 作为安装环境。

(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 

以上安装包,也可以在单独下载后,上传至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

七、 启动nginx

/usr/local/nginx/sbin/nginx

然后测试一下:
使用ps -ef | grep nginx

八、防火墙关掉

方法:

systemctl stop firewalld.service
systemctl disable firewalld.service

然后前台访问: 使用 http://localhost(请换成您机器的ip)

九、 如果想要停止,请使用:

pkill -9 nginx 

十、重启和停止
1、验证nginx配置文件是否正确
方法一:进入nginx安装目录sbin下,输入命令./nginx -t

看到如下显示
nginx.conf syntax is ok

nginx.conf test is successful

2、重启Nginx服务

 进入nginx可执行目录sbin下,输入命令./nginx -s reload 即可

猜你喜欢

转载自blog.csdn.net/qq_24790545/article/details/82594977