【Linux网络配置实验】Web配置

总体流程

服务端

  1. 创建资源目录 mkdir /var/shnwwwv2
  2. 添加认证 cp /data/CN/.htaccess /var/shnwwwv2/.htaccess (不添加登录时,不需要密码)
  3. 配置认证
  4. 添加ht用户 htpasswd -b /etc/httpd/conf.d/auth.txt shnu1 shnu1
  5. 添加网页文件 vim /var/shnwwwv2/index.html
  6. 配置web服务器主配置 vim /etc/httpd/conf/httpd.conf
  7. 重启服务 service httpd restart
https
  1. 创建证书
  2. 创建资源目录 mkdir /var/shnwww
  3. 添加网页文件 vim /var/shnwww/index.html
  4. 配置Https配置文件vim /etc/httpd/conf.d/ssl.conf
  5. 配置web服务器主配置 vim /etc/httpd/conf/httpd.conf 打开210行的https加密
  6. 重启服务 service httpd restart

客户端

  1. 在浏览器中输入网址进行验证 http://www1.shncompany.net.显示出html中的内容.
  2. 在浏览器中输入网址进行验证 http://www2.shncompany.net.需要输入用户与密码(ht用户)
https
  1. 在浏览器中输入网址进行验证 https://www.shncompany.net.我已了解-->添加-->确认

配置认证

bash 复制代码
AuthUserFile /etc/httpd/conf.d/auth.txt
AuthType Basic
AuthName "Auth Page"
require valid-user               
  • AuthUserFile:文件路径 (需要创建文件)

添加网页文件

复制代码
这里是hello world

配置web服务器主配置

yaml 复制代码
210 # Include conf.d/*.conf

1033 <VirtualHost *:80>
1034     servername www1.shncompany.net
1035     documentroot /var/shnwwwv1
1036 </VirtualHost>
1037 
1038 <VirtualHost *:80>
1039     servername www2.shncompany.net
1040     documentroot /var/shnwwwv2
1041 <Directory "/var/shnwwwv2">
1042     Options Indexes MultiViews
1043     AllowOverride all
1044     Order allow,deny
1045     Allow from all
1046 </Directory>
1047 </VirtualHost>
  • 210: 关闭SSL加密 在使用HTTPS时在打开
  • 1034: ServerName 域名
  • 1035: documentroot 资源目录路径
  • 1043: AllowOverride All 允许 .htaccess 覆盖配置。

创建证书

bash 复制代码
# openssl req -x509 -days 365 -newkey rsa:2048 -nodes -keyout /etc/httpd/conf.d/shnserver.key -out /etc/httpd/conf.d/shnserver.crt                                  // 创建 SSL
Generating a 2048 bit RSA private key
.............................................+++
....+++
writing new private key to '/etc/vsftpd/vsftpd.pem'
-----
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) [GB]:cn                                  // 国家
State or Province Name (full name) [Berkshire]:ln                     // 省
Locality Name (eg, city) [Newbury]:ltu                                // 城市
Organization Name (eg, company) [My Company Ltd]:soft                 // 组织
Organizational Unit Name (eg, section) []:network                     // 单位名称
Common Name (eg, your name or your server's hostname) []:localhost    // 主机名称        
Email Address []:

配置Https文件

bash 复制代码
14 DocumentRoot /var/shnwww
15 ServerName www.shncompany.net:443

22 SSLCertificateFile /etc/httpd/conf.d/shnserver.crt
23 SSLCertificateKeyFile /etc/httpd/conf.d/shnserver.key
相关推荐
huangyuchi.4 分钟前
【Linux】环境变量
linux·运维·操作系统·环境变量·系统调用·命令行参数·main函数参数
Crazy________2 小时前
28Rsync免密传输与定时备份
linux·运维·服务器
阿巴~阿巴~3 小时前
信号产生机制全解析:从硬件异常到软件触发的深度探索
linux·运维·服务器
坐望云起3 小时前
Hyper-V + Centos stream 9 搭建K8s集群(一)
linux·kubernetes·centos
sky北城5 小时前
linux基本系统服务——DNS服务
linux·运维·服务器
心一信息9 小时前
如何在Ubuntu上部署excalidraw
linux·运维·ubuntu
人生匆匆9 小时前
linux ext4缩容home,扩容根目录
linux·运维·服务器
Linux技术芯9 小时前
#Linux内存管理#缺页中断处理的核心函数是do_page_fault()的工作原理
linux
yuanzhengme10 小时前
Shell【脚本 02】离线安装配置Zookeeper及Kafka并添加service服务和开机启动(脚本分析)
linux·zookeeper·kafka·自动化·安装脚本
Johny_Zhao10 小时前
阿里云平台健康检查巡检清单-运维篇
linux·网络安全·阿里云·信息安全·云计算·shell·系统运维