当前位置: 首页 > article >正文

Linux的web服务器

www简介

Web网络服务也叫WWW(World Wide Web 全球信息广播)万维网服务,一般是指能够让用户通过浏 览器访问到互联网中文档等资源的服务

Web 网络服务是一种被动访问的服务程序,即只有接收到互联网中其他主机发出的请求后才会响 应,最终用于提供服务程序的 Web 服务器会通过 HTTP(超文本传输协议)或HTTPS(安全超文本 传输协议)把请求的内容传送给用户

状态代码:

由三位数字组成,第一个数字定义了响应的类别,且有五种可能取值

1xx:指示信息 —— 表示请求已接收,继续处理

2xx:成功 —— 表示请求已被成功接收、理解、接

3xx:重定向 —— 要完成请求必须进行更进一步的操作

4xx:客户端错误 —— 请求有语法错误或请求无法实现

5xx:服务器端错误 —— 服务器未能实现合法的请求

常见状态代码、状态描述的说明如下:

200 OK:客户端请求成功

400 Bad Request:客户端请求有语法错误,不能被服务器所理解

401 Unauthorized:请求未经授权,这个状态代码必须和 WWW-Authenticate 报头域一起使用

403 Forbidden:服务器收到请求,但是拒绝提供服务

404 Not Found:请求资源不存在,举个例子:输入了错误的URL

500 Internal Server Error:服务器发生不可预期的错误

503 Server Unavailable:服务器当前不能处理客户端的请求,一段时间后可能恢复正常

使用nginx搭建web网站

nginx简介

Nginx是一款轻量级HTTP服务器,也是一款邮箱代理服务器,同时具备反向代理、通用TCP/UDP代理的功能

Nginx可以运行在x86、ARM等多种平台上,同时支持Linux、Windows等主流的操作系统

部署Nginx

 [root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# yum install nginx -y
[root@server ~]# nginx -V # 查看版本,编译器、配置参数等信息
[root@server ~]# systemctl start nginx # 启动httpd
[root@server ~]# systemctl enable nginx # 设置开机启动
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service →
/usr/lib/systemd/system/nginx.service.
[root@server ~]# systemctl status nginx # 查看状态,q键退出查看
[root@server ~]# ps -ef | grep nginx # 查看进程
# 测试,Windows中打开浏览器输入服务器IP地址

实验 

1.基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!

2.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站

[www.openlab.com/student](http://www.openlab.com/student) 网站访问学生信息;[www.openlab.com/data](http://www.openlab.com/data)网站访问教学资料;
​[www.openlab.com/money](http://www.openlab.com/money网站访问缴费网站)。

3.要求 
​     (1)学生信息网站只有song和tian两人可以访问,其他用户不能访问。

     (2)访问缴费网站实现数据加密基于https访问。

1、准备阶段

[root@server ~]# setenforce 0  #SElinux改为宽容模式
[root@server ~]# systemctl stop firewalld  #关闭防火墙
[root@server ~]# systemctl disable firewalld  #取消开机自启防火墙
[root@server ~]# yum install nginx -y  #下载nginx
[root@server ~]# nginx -V # 查看版本,编译器、配置参数等信息
[root@server ~]# systemctl start nginx # 启动httpd
[root@server ~]# systemctl enable nginx # 设置开机启动

一、基于域名[www.openlab.com](http://www.openlab.com)可以访问网站内容为 welcome to openlab!!!

 2、快速搭建www.openlab.com网站(usr/share/nginx/html/index.html为默认网页)

[root@localhost ~]# vim /etc/nginx/nginx.conf  #进入主配置文件

   root         /usr/share/nginx/html;   #找到默认路径

[root@localhost ~]# cd /usr/share/nginx/html/  #进入存放默认网页的目录

[root@localhost html]# cp index.htm index.htm.bak  #将原有的网页进行备份
[root@localhost html]# echo 'welcome to openlab' > index.html  #将要求写入新的文件中

[root@localhost html]# nginx -t  #测试
        nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
        nginx: configuration file /etc/nginx/nginx.conf test is successful  #成功

[root@localhost html]# systemctl restart nginx.service   #重启服务

windows的C:\Windows\System32\drivers\etc\hosts文件中添加域名
192.168.88.8 www.openlab.com 

浏览器中访问

http://www.openlab.com

 默认页面的内容

 谷歌浏览器访问http://www.openlab.com

二、给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站

3.给该公司创建三个子界面分别显示学生信息,教学资料和缴费网站

[root@localhost /]# mkdir www  #在根目录创建www目录(子目录不能放在根目录)

[root@localhost www]# mkdir student data money  #在www目录中创建三个子目录

[root@localhost student]# touch index.html  #在子目录中创建index.html配置文件
[root@localhost data]# touch index.html  #在子目录中创建index.html配置文件

[root@localhost money]# touch index.html  #在子目录中创建index.html配置文件

[root@localhost student]# echo 'Student Information ' > index.html  #将要求写入新的文件中

[root@localhost data]# echo 'Teaching materials ' > index.html  #将要求写入新的文件中

[root@localhost money]# echo 'Payment website ' > index.html  #将要求写入新的文件中

4.创建虚拟主机

[root@localhost nginx]# vim /etc/nginx/nginx.conf  #主配置文件

        include /etc/nginx/conf.d/*.conf;  #当主配置文件中找不到配置时,将跳转至改目录下

[root@localhost ~]# cd /etc/nginx/conf.d/  #在该目录下创建虚拟主机

[root@localhost conf.d]# vim virtualhost.conf  #创建虚拟网站配置文件

5.编写配置文件(将data文件写入虚拟网站配置文件中)

[root@localhost conf.d]# vim virtualhost.conf   #编辑文件配置

        server { #创建student子目录网站
                listen 80;                                                  #端口号80
                server_name www.openlab.com;           #域名
                location /data {    
                        alias /www/data/;                            #路径(alias别名结尾加 ‘ / ’ )
                        index index.html index.htm;
    }

[root@localhost html]# nginx -t  #测试
        nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
        nginx: configuration file /etc/nginx/nginx.conf test is successful  #成功

[root@localhost html]# systemctl restart nginx.service   #重启服务

谷歌浏览器访问http://www.openlab.com/data

三、学生信息网站只有song和tian两人可以访问,其他用户不能访问。

6、创建song、tian 两个用户

[root@localhost nginx]# yum install httpd-tools -y  #生成用户认证文件,安装htpassword

[root@server wwww]# htpasswd -c .stupasswd song #新建song用户(首次创建需要加-c参数)
        New password:123 #创建密码
                Re-type new password:123 #确认密码
                Adding password for user song

[root@server www]# htpasswd -b .stupasswd tian 123 #新建tian用户(-b,直接加密码无需交互)
 

 7、编辑虚拟网站配置文件

[root@localhost conf.d]# vim virtualhost.conf   #编辑文件配置

server {                         #需要将两个子目录放在同一个server中,用不同的location区分
        listen 80;
        server_name www.openlab.com;
        location /student {
                alias /www/student/;
                index index.html index.htm;

                auth_basic "Restricted";      #用户的访问控制
               auth_basic_user_file /www/stupasswd;  #用户信息文件路径
        }
       

                                        #data配置
        location /data {
                alias /www/data/;
                index index.html index.htm;
        }
}

[root@localhost html]# nginx -t  #测试
        nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
        nginx: configuration file /etc/nginx/nginx.conf test is successful  #成功

[root@localhost html]# systemctl restart nginx.service   #重启服务 

无法访问 

四、访问缴费网站实现数据加密基于https访问。

8、创建私钥

# 在/etc/nginx目录下制作整数所用的私钥文件web2.key
[root@server ~]# openssl genrsa -aes128 2048 > /etc/nginx/money.key
密码:000000

9、制作证书

# 制作证书
[root@server ~]# openssl req -utf8 -new -key /etc/nginx/money.key -x509 -days 365 -out /etc/nginx/money.crt
密码:000000

# 注意:下列证书信息项目,在面试时常问
Country Name (2 letter code) [AU]:86 # 国家代码
State or Province Name (full name) [Some-State]:shh # 省份
Locality Name (eg, city) []:xi'an # 城市
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 # 邮箱

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

10、修改配置文件

[root@localhost ~]# vim /etc/nginx/conf.d/virtualhost.conf 

server{                                         #端口号不同,所以建立新的server配置

    listen       443 ssl;  #端口
    server_name  www.openlab.com;  #域名

    ssl_certificate      /etc/nginx/money.crt;  #公钥
    ssl_certificate_key  /etc/nginx/money.key;  #私钥

    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

    location /money {
        alias   /www/money/;  #访问配置目录
        index  index.html index.htm;
    }
}
 

[root@localhost html]# nginx -t  #测试
        nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
        nginx: configuration file /etc/nginx/nginx.conf test is successful  #成功

[root@localhost html]# systemctl restart nginx.service   #重启服务 

虚拟配置文件


http://www.kler.cn/a/416464.html

相关文章:

  • Node.js的url模块与querystring模块
  • 【AI日记】24.11.29 kaggle 比赛 Titanic-2 | 鼓励自己
  • AI生成式安全威胁:企业数据将如何被重新定义?
  • wordpress使用Markdown语法写的文章图片显示不正常,记录一次折腾之旅
  • 【vue3实现微信小程序】设置项目底部tab页面切换标签
  • 计算机网络——不同版本的 HTTP 协议
  • Webpack 的构建流程
  • 分布式储能监控系统为储能电站高效运维与精细化管理赋能
  • Vue 3 的双向绑定原理
  • go结构体匿名“继承“方法冲突时继承优先顺序
  • doris避坑之端口冲突
  • uniapp在小程序连接webScoket实现余额支付
  • LED室内显示屏的性能优化分析和电压管理
  • 外卖商城平台的微信小程序ssm+论文源码调试讲解
  • Nvidia 推出最新 AI 音频模型,可制作前所未有的声音
  • Hive元数据表解析
  • dbeaver如何批量执行sql脚本
  • 像素流送api ue多人访问需要什么显卡服务器
  • 【Python】Selenium模拟在输入框里,一个字一个字地输入文字
  • Ubuntu中的apt update 和 apt upgrade