Nginx--安装

1、介绍

Nginx(“engine x”)是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器和轻量级的web服务器。
官网:http://nginx.org/
中文文档:http://www.nginx.cn/doc/

2、安装

本文介绍CentOS平台源码安装:配置、编译、安装三部曲
工具安装:
gcc编译器、pcre进行URL重写、zlib和zlib-devel进行解压缩

yum -y install gcc pcre-devel zlib zlib-devel

安装wget获取源码包:

yum -y install wget

安装在/usr/src下:

wget http://nginx.org/download/nginx-1.17.1.tar.gz -P /usr/src

查看下载的安装包:

du -h /usr/src/nginx-1.17.1.tar.gz

解压:

cd /usr/src
tar xf nginx-1.17.1.tar.gz

解压后出现源码包,进入源码包进行编译:

cd /usr/src/nginx-1.17.1

安装:

./configure --prefix=/usr/local/nginx
make
make install

查看nginx命令帮助文档:

/usr/local/nginx/sbin/nginx -?

安装过程没有出现error,则大功告成!

文件介绍:
|安装目录| /usr/local/nginx |
|启动文件| /usr/local/nginx/sbin/nginx|
|模块文件| /usr/local/nginx/modules |
|配置文件| /usr/local/nginx/conf/nginx.conf |
|pid文件| /usr/local/nginx/logs/nginx.pid|
|错误日志| /usr/local/nginx/logs/error.log|
|访问日志| /usr/local/nginx/logs/access.log|

查看端口是否被占用:
Nginx默认端口为80,修改nginx.conf将端口设置为所需要的端口,启动前先查看所设置端口是否被占用
以下两种方式查看80端口使用情况:

lsof -i :80
netstat -ntpl|grep 80

端口未被占用则进行后续启动
启动:

/usr/local/nginx/sbin/nginx

两种方式验证是否安装成功:

浏览器输入ip地址出现 Welcome to nginx!

使用文本浏览器进行访问(无缓存,推荐使用)

安装 yum -y install elinks
访问 elinks http://ip --dump

出现Welcome to nginx!
安装完成!

杀死全部启动进程和子进程:

pkill nginx

安装 yum -y install psmisc
killall nginx
查看端口是否使用 lsof -i :80

3、隐藏服务器内核

编辑配置文件

[root@localhost nginx-1.16.1]# cd /usr/src/nginx-1.16.1
[root@localhost nginx-1.16.1]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@localhost nginx-1.16.1]# vim src/core/nginx.h

#修改如下配置
#define NGINX_VERSION      "1.8"
#define NGINX_VER          "MYWS/" NGINX_VERSION

重新编译

[root@localhost nginx-1.16.1]# ./configure --prefix=/usr/local/nginx
checking for OS
 + Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
...

安装

[root@localhost nginx-1.16.1]# make && make install

重启服务进行访问
在这里插入图片描述

发布了34 篇原创文章 · 获赞 1 · 访问量 535

猜你喜欢

转载自blog.csdn.net/weixin_42440154/article/details/95085785