五分钟学会搭建web网站

本文详细描述了如何在Linux服务器上设置DNS映射,安装Nginx和Apache,创建并管理www.openlab.com的不同子站点(如数据、学生信息和缴费),以及配置SSL证书和HTTP基本认证。
摘要由CSDN通过智能技术生成

一、准备工作

关闭安全软件

安装所需软件

[root@Server ~]# yum install nginx httpd-tools -y

C:\Windows\System32\drivers\etc\hosts 文件进行DNS映射

192.168.205.137 www.openlab.com

第二步:创建www.openlab.com网站

#创建网页目录及网页

[root@Server ~]# mkdir -p /www/openlab
[root@Server ~]# echo 'welcome to openlab' > /www/openlab/index.html
[root@Server ~]# vim /etc/nginx/nginx.conf

server {
        listen       80;
        server_name  www.openlab.com;
        root         /www/openlab;

        # Load configuration files for the default server block.
    }


[root@Server ~]# systemctl start nginx

测试

window端打开浏览器输入www.openlab.com测试

第三步:创建教学资料子网站www.openlab,com/data

[root@Server ~]# mkdir /www/openlab/data
[root@Server ~]# echo 'data' > /www/openlab/data/index.html
[root@Server ~]# vim /etc/nginx/nginx.conf

        location /data{
                        alias /www/openlab/data;
                        index index.

}

[root@Server ~]# systemctl restart nginx

window端打开浏览器输入www.openlab.com/data测试

第四步:创建学生信息子网站www.openlab.com/student

[root@Server ~]# vim /etc/nginx/nginx.conf
[root@Server ~]# mkdir /www/openlab/student
[root@Server ~]# echo 'student' > /www/openlab/student/index.html

[root@Server ~]# useradd song
[root@Server ~]# passwd song            #密码123456

[root@Server ~]# useradd tian              #密码654321
[root@Server ~]# passwd tian

[root@Server ~]# htpasswd -c /etc/nginx/passwd song    #密码123456

[root@Server ~]# htpasswd /etc/nginx/passwd tian         #密码654321

[root@Server ~]# vim /etc/nginx/nginx.conf

location /student
                        {
                        alias /www/openlab/student;
                        index index.html index.htm;
                        auth_basic "please input password";
                        auth_basic_user_file /etc/nginx/passwd;
                        }

[root@Server ~]# systemctl restart nginx

window端打开浏览器输入www.openlab.com/student测试

第五步:创建缴费子网站www.openlab.com/money

mkdir /www/openlab/money
[root@Server ~]# echo 'money' > /www/openlab/money/index.html
[root@Server ~]# openssl genrsa -aes128 2048 > /etc/nginx/money.key
Generating RSA private key, 2048 bit long modulus (2 primes)
...+++++
........................................................................+++++
e is 65537 (0x010001)

Enter pass phrase:
Verifying - Enter pass phrase:
[root@Server ~]# openssl req -utf8 -new -key /etc/nginx/money.key -x509 -days 365 -out /etc/nginx/money.crt
Enter pass phrase for /etc/nginx/money.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) []:server
Email Address []:andy@qq.com

去除私钥的加密密码

[root@Server ~]# cd /etc/nginx
[root@Server nginx]# cp money.key money.key.org
[root@Server nginx]# openssl rsa -in money.key.org -out money.key
Enter pass phrase for money.key.org:

[root@Server nginx]# vim /etc/nginx/nginx.conf

增加以下内容

 server {
                        listen       443 ssl http2;
                        server_name  www.openlab.com;
                        location /money {
                                                alias /www/openlab/money;
                                                index index.html index.htm;
                                        }
                        ssl_certificate         "/etc/nginx/money.crt";
                        ssl_certificate_key     "/etc/nginx/money.key";
                        }

[root@Server nginx]# systemctl restart nginx

此网站需要location二次映射

1、只要监听端口号变,就要重新增加入口段,入口不一样

2、只要server_name变,就得重新增加server段

window端打开浏览器输入www.openlab.com/money测试

实验完毕!!!

  • 14
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值