一、NGINX简介
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮(IMAP/POP3)代理服务器,由俄罗斯的程序设计师Igor Sysoev所开发,其特点是占有内存少,并发能力强。事实上nginx的并发能力确实在同类型的网页服务器中表现较好。
二、安装NGINX
1、获取Nginx
Nginx的官方主页: http://nginx.org
2、关闭防火墙关闭selinux
[root@edu.com ~]# systemctl stop firewalld #关闭防火墙
[root@edu.com ~]# systemctl disable firewalld #开机关闭防火墙
[root@edu.com ~]# setenforce 0 #临时关闭selinux
[root@edu.com ~]# getenforce #查看selinux状态
3、NGINX的安装
Yum方式:
[root@edu.com ~]# cd /etc/yum.repos.d/
[root@edu.com yum.repos.d]# vi nginx.repo #编写nginx的yum源
[nginx]
name=nginx
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
[root@edu.com yum.repos.d]# yum clean all
[root@edu.com yum.repos.d]# yum makecache
[root@edu.com ~]# yum install -y nginx #安装nginx
[root@edu.com ~]# systemctl start nginx #启动
[root@edu.com ~]# systemctl restart nginx #重启
[root@edu.com ~]# systemctl enable nginx #开机启动
[root@edu.com ~]# systemctl stop nginx #关闭
查看nginx状态
[root@qfedu.com ~]# ps aux | grep nginx
root 3927 0.0 0.0 46384 968 ? Ss 18:46 0:00 nginx: master
process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 3928 0.0 0.1 46792 1932 ? S 18:46 0:00 nginx: worker
process
root 3932 0.0 0.0 112660 968 pts/1 R+ 18:47 0:00 grep --
color=auto nginx
2.查看nginx端口
[root@qfedu.com ~]# netstat -lntp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
3927/nginx: master
#注意:nginx默认端口为80
3.测试主页是否可以访问:
[root@qfedu.com ~]# curl -I http://127.0.0.1
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Sat, 16 Nov 2019 10:49:48 GMT
Content-Type: text/html
Content-Length: 635
Last-Modified: Fri, 11 Oct 2019 06:45:33 GMT
Connection: keep-alive
ETag: "5da0250d-27b"
Accept-Ranges: bytes
nginx主配置文件
/etc/nginx/nginx.conf
nginx虚拟主机配置文件
[root@qfedu.com ~]# vi /etc/nginx/conf.d/default.conf
server {
listen 80; #监听的端口
server_name localhost; #设置域名或主机名
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main; #日志存放路径
location / { #请求级别:匹配请求路径
root /usr/share/nginx/html; #默认网站发布目录
index index.html index.htm; #默认打开的网站主页
}