## **linux服务器nginx的安装**

系统:Centos7 64位
Nginx: http://nginx.org/en/download.html 目前最新版本1.15.7
nginx

下载模块依赖性Nginx需要依赖下面3个包
1.gzip 模块需要 zlib 库 ( 下载: http://www.zlib.net/ )
2.rewrite 模块需要 pcre 库 ( 下载: https://ftp.pcre.org/pub/pcre)
3.ssl 功能需要 openssl 库 ( 下载: http://www.openssl.org/ )

依赖包安装顺序依次为:openssl、zlib、pcre, 然后安装Nginx包
wget http://www.openssl.org/source/openssl-fips-2.0.9.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz
wget https://ftp.pcre.org/pub/pcre/pcre2-10.32.tar.gz或yum -y install pcre-devel
wget http://nginx.org/download/nginx-1.15.7.tar.gz
如果没有安装c++编译环境,还得安装,通过yum install gcc-c++完成安装

下一步,编译安装
openssl :

[root@bogon] tar zxvf openssl-fips-2.0.9.tar.gz

[root@bogon] cd openssl-fips-2.0.9

[root@bogon openssl-fips-2.0.9] ./config && make && make install

pcre:

[root@bogon] tar zxvf pcre-2-10.32.tar.gz

[root@bogon] cd pcre-2-10.32

[root@bogon pcre-2-10.32] ./configure && make && make install

zlib:

[root@bogon]tar zxvf zlib-1.2.11.tar.gz

[root@bogon] cd zlib-1.2.11

[root@bogon zlib-1.2.11] ./configure && make && make install

最后安装nginx

[root@bogon]tar zxvf nginx-1.15.7.tar.gz

[root@bogon] cd nginx-1.15.7

[root@bogon nginx-1.15.7] ./configure && make && make install

安装完成后,可启动nginx:
[root@bogon ~]# whereis nginx
nginx: /usr/local/nginx
[root@bogon ~]# cd /usr/local/nginx
[root@bogon nginx]# ll
总用量 4
drwxr-xr-x. 2 root root 4096 12月 2 11:08 conf
drwxr-xr-x. 2 root root 40 12月 2 11:08 html
drwxr-xr-x. 2 root root 6 12月 2 11:08 logs
drwxr-xr-x. 2 root root 19 12月 2 11:08 sbin
[root@bogon nginx]# sbin/nginx

查看是否已启动:
[root@bogon nginx]# ps -aux|grep nginx
root 37362 0.0 0.0 20552 616 ? Ss 11:09 0:00 nginx: master process sbin/nginx
nobody 37364 0.0 0.1 23088 1392 ? S 11:09 0:00 nginx: worker process
root 37398 0.0 0.0 112720 984 pts/2 S+ 11:10 0:00 grep --color=auto nginx

通过浏览器访问:
在这里插入图片描述
成功!!

到这个就说明nginx安装并启动成功。

启动:/usr/local/nginx/sbin/nginx
停止/重新加载:/usr/local/nginx/sbin/nginx -s stop(quit、reload)
验证配置文件是否合法:/usr/local/nginx/sbin/nginx -t
命令帮助:/usr/local/nginx/sbin/nginx -h

小弟第一次写博客,有不足之处请指出,谢谢!

猜你喜欢

转载自blog.csdn.net/weixin_41982982/article/details/84704061