CENTOS7 Nginx 服务的搭建与配置

一、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; #默认打开的网站主页
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值