美文网首页
nginx的安装和配置网站

nginx的安装和配置网站

作者: 南南宫问天 | 来源:发表于2020-05-09 15:05 被阅读0次

1.关闭selinux和防火墙

[root@web02 ~]# systemctl stop firewalld ; systemctl disable firewalld
[root@web02 ~]# setenforce 0 ; sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/sysconfig/selinux

2.添加nginx官方源

[root@web02 ~]# cat /etc/yum.repos.d/nginx.repo 
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

3.安装nginx,然后启动nginx并加入开机自启

[root@web02 ~]# yum install -y nginx
[root@web02 ~]# systemctl start nginx ; systemctl enable nginx
[root@web02 czq]# netstat -lnp | grep ":80"  ##查看端口看有没有启动成功
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      26717/nginx: master 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      26717/nginx: master 

4.配置nginx配置文件

[root@web02 ~]# cd /etc/nginx/conf.d/
[root@web02 conf.d]# cat www.conf 
server{
    listen  80;  ##设置监听端口
    server_name    www.czq.com; ##设置访问域名
    location / {  ##定义站点目录
    root    /usr/share/nginx/html; ##存放主页文件的目录
    index czq.html; ##主页文件
}
}

5.找开发要主页文件代码并存放在主页文件

[root@web02 conf.d]# cd /usr/share/nginx/html/
[root@web02 czq]# cat czq.html 
<p>
    <strong><span style="color:#60D978;">i am czq</span></strong> 
</p>
<p>
    <strong><span style="color:#60D978;">from lcvc<img src="http://kindeditor.net/ke4/plugins/emoticons/images/8.gif" border="0" alt="" /></span></strong> 
</p>
<p>
    <strong><span style="color:#60D978;">email 2484576482@qqcom</span></strong> 
</p>

6.重启nginx服务

[root@web02 czq]# systemctl restart nginx

7.填写解析信息

1.可以在阿里云添加DNS解析记录配置
2.或者可以在客户机的hosts文件上配置或者通过DNS服务器解析
czq@sunlog:~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 sunlog

The following lines are desirable for IPv6 capable hosts

::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.16.210.52 www.czq.com

8.访问测试

image.png

相关文章

网友评论

      本文标题:nginx的安装和配置网站

      本文链接:https://www.haomeiwen.com/subject/gasknhtx.html