使用nginx搭建一个网站

使用nginx搭建一个网站

1. 恢复快照

[root@server ~]# setenforce 0
setenforce: SELinux is disabled       

[root@server ~]# systemctl status firewalld
○ firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabl>
     Active: inactive (dead)
       Docs: man:firewalld(1)
 
[root@server ~]# yum -y install nginx

[root@server ~]# systemctl start  nginx   # 启动nginx
 
[root@server ~]# systemctl enable  nginx  # 设置开机启动

2. 新建网络目录并建立网页

[root@server ~]# mkdir  -p  /www/file

#写入网站数据
[root@server ~]# echo  "this is my web"  >  /www/file/index.html  

3. 建立本地hosts域名映射

[root@server ~]# vim /etc/hosts
 # 添加如下内容: 192.168.48.130  www.openlab.com //添加自己的ip

4. 建立file网站

[root@server ~]# vim /etc/nginx/nginx.conf
#添加内容如下
server {
                listen       80;
             
             server_name  www.openlab.com;
                location   /file {
                                        alias /www/file/;
                                        index index.html index.htm;
                                }
           }

在这里插入图片描述

5. 建立https的file网站

[root@server ~]# openssl  genrsa  -aes128  2048 > /etc/nginx/file.key
Generating RSA private key, 2048 bit long modulus (2 primes)
.................................................................................................+++++
.........................+++++
e is 65537 (0x010001)
Enter pass phrase:        //密码:1234
Verifying - Enter pass phrase:       //再次输入

# 制作证书
[root@server ~]# openssl  req  -utf8  -new  -key  /etc/nginx/file.key  -x509  -days  365  -out  /etc/nginx/file.crt
Enter pass phrase for /etc/nginx/file.key:    # 需要输入加密私钥的密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
# 注意:下列证书信息项目
Country Name (2 letter code) [AU]:86							  # 国家代码
State or Province Name (full name) [Some-State]:ningxia		  # 省份
Locality Name (eg, city) []:yinchuan                                      #市 
Organization Name (eg, company) [Internet Widgits Pty Ltd]:openlab    #公司
Organizational Unit Name (eg, section) []:rhce   #职位
Common Name (e.g. server FQDN or YOUR name) []:xiaochen    #姓名
Email Address []:123456@qq.com     #邮箱

# 在加载SSL支持的Nginx并使用上述私钥时除去必须的口令
[root@server ~]# cd  /etc/nginx
[root@server nginx]# cp  file.key  file.key.org
[root@server nginx]# openssl rsa -in file.key.org -out file.key
Enter pass phrase for file.key.org:  # 输入加密私钥的密码
writing RSA key

 # 编辑配置文件
[root@server ~]# vim  /etc/nginx/nginx.conf    
server {
                listen       443 ssl http2;
                server_name  www.openlab.com;
                location /ftp {
                                        alias         /www/file;
                                        index  index.html  index.htm;
                                }
                ssl_certificate       "/etc/nginx/file.crt";
                ssl_certificate_key   "/etc/nginx/file.key";
        }

[root@server nginx]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

在这里插入图片描述

6. 重启服务

[root@server nginx]# systemctl restart nginx

7. 测试

输入www.openlab.com/file
或https://www.openlab.com/file

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值