web服务器

发布于:2024-12-07 ⋅ 阅读:(104) ⋅ 点赞:(0)

一、简介

1.什么是www

www world wide web 的缩写,也就是全球信息广播的意思。通常说的上网就是使用 www 来查询用户所需要的信息。www 可以结合文字、图形、影像以及声音等多媒体,并通过可以让鼠标单击超链接的方式将信息以Internet 传递到世界各处去。
2.网址以及http简介
        在nginx中,这个 目录默认 /usr/share/nginx/html/
        
URL Uniform Resource Locator ,统一资源定位符,对可以从互联网上得到的资源的位置和访问
方法的一种简洁的表示,是互联网上标准资源的地址。
HTTP 报文: http 报文中有很多行内容,这些行的字段内容都是由一些 ASCII 码串组成,但各个字段
的长度是不同的。 http 报文可分为两种,一种是从 web 客户端发往 web 服务器的 http 报文,称为请
求报文。另外一种是从 web 服务器发往 web 客户端的报文,称为响应报文 。
        ·http请求报文由请求行、请求头部、空行和请求报文主体几个部分组成
        · http 响应报文由起始行、响应头部、空行和响应报文主体这几个部分组成

二、web服务器的类型

1.仅提供用户浏览的单向静态网页

2.提供用户互动接口的动态网站

三、web服务器基本配置

[root@localhost ~]# dnf install nginx -y
[root@localhost ~]# nginx -v
[root@localhost ~]# nginx -V
[root@localhost ~]# rpm -ql nginx
[root@localhost httpd]# tree /etc/nginx
[root@localhost ~]# tree /etc/nginx/
/etc/nginx/
├── conf.d #子配置文件目录
├── default.d
├── fastcgi.conf
├── fastcgi.conf.default
├── fastcgi_params #用以翻译nginx的变量供php识别
├── fastcgi_params.default
├── koi-utf
├── koi-win
├── mime.types #用以配置支持的媒体文件类型
├── mime.types.default
├── nginx.conf #主配置文件
├── nginx.conf.default
├── scgi_params
├── scgi_params.default
├── uwsgi_params #用以配置nginx的变量供python识别
├── uwsgi_params.default
└── win-utf
[root@localhost ~]# tree /usr/share/nginx/html/ 
[root@localhost ~]# tree /var/log/nginx/ 

[root@localhost ~]# grep ^[^#] /etc/nginx/nginx.conf

[root@localhost ~]#systemctl disable firewalld --now
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# systemctl restart nginx
[root@localhost ~]# curl -I localhost

四、虚拟主机配置实战

1.搭建静态网页
[root@localhost ~]# echo "hello world" >//usr/share/nginx/html/index.html 
[root@localhost ~]# curl localhost
hello world
[root@localhost ~]# curl 192.168.137.130
hello world

2.建立两个基于ip地址访问的网站

该网站 ip 地址的主机位为 100 ,设置首页目录为 /www/ip/100 ,网页内容为: this is 100 。
该网站 ip 地址主机位为 200 ,设置首页目录为 /www/ip/200 ,网页内容为: this is 200 。

[root@localhost ~]# nmtui
[root@localhost ~]# nmcli connection up ens33
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/3)
[root@localhost ~]# mkdir -pv /www/ip/{100,200}
[root@localhost ~]# echo this is 100 >/www/ip/100/index.html
[root@localhost ~]# echo this is 200 > /www/ip/200/index.html
[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce
Permissive
[root@localhost ~]# vim /etc/nginx/conf.d/test_ip.conf
[root@localhost ~]# systemctl restart nginx  //重启nginx服务
[root@localhost ~]# curl 192.168.137.100
this is 100
[root@localhost ~]# curl 192.168.137.200
this is 200

建立两个基于不同端口访问的网站:

建立一个使用 web 服务器默认端口的网站,设置网站首页目录为 /www/port/80 ,网页内容为: the
port is 80 。
建立一个使用 10000 端口的网站,设置网站首页目录为 /www/port/10000 ,网页内容为: the port
is 10000 。

建立两个基于域名访问的网站:

新建一个网站,域名为 www.ceshi.com ,设置网站首页目录为 /www/name ,网页内容为 this is
test 。
新建一个网站,域名为 rhce.first.day ,同时可通过 ce.first.day 访问,设置网站首页目录
为 /www/ce, 网页内容为: today is first day of class 。

[root@localhost ~]# mkdir /www/{name,ce}
[root@localhost ~]# echo this is test > /www/name/index.html
[root@localhost ~]# echo today if first day of class > /www/ce/index.html
[root@localhost ~]# vim /etc/nginx/conf.d/test_servername.conf
[root@localhost ~]# vim /etc/hosts
[root@localhost ~]# systemctl restart nginx

基于虚拟目录和用户控制的web网站

添加一个IP为192.168.137.135

[root@localhost ~]# nmtui
[root@localhost ~]# nmcli connection up ens33
连接已成功激活(D-Bus 活动路径:/org/freedesktop/NetworkManager/ActiveConnection/8)
[root@localhost ~]# vim /etc/nginx/conf.d/test_virtualdir.conf
[root@localhost ~]# mkdir /www/real/
[root@localhost ~]# echo real-virtual > /www/real/index.html
[root@localhost ~]# systemctl  restart nginx
[root@localhost ~]# curl 192.168.137.135/real/
real-virtual

用户访问控制


[root@localhost ~]# dnf install httpd-tools -y
[root@localhost ~]# htpasswd -cb /etc/nginx/conf.d/auth-password user1
123456
[root@localhost ~]# systemctl restart nginx

搭建静态网站


[root@localhost ~]# nmtui   //添加一个IP地址为192.168.30.156提供给https
[root@localhost ~]# nmcli connection up ens33
[root@localhost ~]# mkdir -pv /www/https/
[root@localhost ~]# echo https > /www/https/index.html
[root@localhost conf.d]# cd /etc/pki/tls/certs/
[root@localhost certs]# openssl genrsa -out https.key   //key是私钥文件
[root@localhost certs]# openssl req -utf8 -new -key https.key -x509 -days 100 -out https.crt
[root@localhost ~]# cat /etc/nginx/conf.d/test_https.conf10

网站公告

今日签到

点亮在社区的每一天
去签到