网站设计排版怎么做,wordpress添加媒体,网站怎么做二级域名,淄博网站WEB服务器
1、WEB服务简介
# 目前最主流的三个Web服务器是Apache、Nginx、 IIS。
- WEB服务器一般指网站服务器#xff0c;可以向浏览器等Web客户端提供网站的访问#xff0c;让全世界浏览。
- WEB服务器也称为WWW(WORLD WIDE WEB)服务器#xff0c;主要功能是提供网上信息…WEB服务器
1、WEB服务简介
# 目前最主流的三个Web服务器是Apache、Nginx、 IIS。
- WEB服务器一般指网站服务器可以向浏览器等Web客户端提供网站的访问让全世界浏览。
- WEB服务器也称为WWW(WORLD WIDE WEB)服务器主要功能是提供网上信息浏览服务。
- WEB服务器是一种被动程序只有当Internet上运行其他计算机中的浏览器发出的请求时服务器才会响应2、WEB 服务协议
# WEB 服务应用层使用HTTP协议。
# HTML标准通用标记语言格式的文件。
# 浏览器通过统一资源定位器URL去访问web服务。
# 为了解决HTTP协议的这一缺陷需要使用另一种协议安全套接字层超文本传输协议HTTPS。为了数据传输的安全HTTPS在HTTP的基础上加入了SSL协议SSL依靠证书来验证服务器的身份并为浏览器和服务器之间的通信加密。
# WEB服务采用的是浏览器/服务器结构web服务器只能解析静态页面。 动态页面:只要和数据库进行连接的都属于动态页面比如java写的代码PHP的代码python的代码。web服务器:apache nginx IIS #端口全部为80!https为443端口前端页面:静态元素: .html .img js css swf 配合:apache、nginx.
后端页面:动态元素:根据不同的开发语言: .php .jsp .py 配合java、php、python专门解析php代码的web中间件(web容器)--php-fpm端口9000
专门解析java代码的web中间件--tomcat(8080).
专门解析python代码的web中间件 ---uwsgi(5000)SQL
数据库:mysql、mariadbApache 服务的搭建与配置
Apache 介绍
Apache HTTP Server简称Apache是Apache软件基金会的一个开放源码的网页服务器Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上由于其跨平台和安全性被广泛使用是最流行的Web服务器端软件之一。
Apache的主程序名叫httpd。一、apache安装
[rootqfedu.com ~]# systemctl stop firewalld
[rootqfedu.com ~]# systemctl disable firewalld
[rootqfedu.com ~]# setenforce 0
[rootqfedu.com ~]# yum install -y httpd
[rootqfedu.com ~]# systemctl start httpd
[rootqfedu.com ~]# netstat -lntp | grep 80 #查看apache端口
tcp6 0 0 :::80 :::* LISTEN 2776/httpd
#端口80.可以改index.html:默认访问网站的主页名称
默认发布网站的目录:/var/www/html1.apache目录介绍
apache的工作目录:
conf 存储配置文件
conf.d 存储配置子文件
logs 存储日志
modules 存储模块
run 存储Pid文件,存放的pid号码。是主进程号认识主配置文件:
# vim /etc/httpd/conf/httpd.conf
ServerRoot /etc/httpd #定义工作目录
Listen 80 #监听端口
Listen 192.168.2.8:80 指定监听的本地网卡 可以修改
User apache # 子进程的用户有可能被人改称www账户
Group apache # 子进程的组
ServerAdmin rootlocalhost # 设置管理员邮件地址
DocumentRoot /var/www/html # 发布网站的默认目录想改改这里。
IncludeOptional conf.d/*.conf # 包含conf.d目录下的所有*.conf配置文件# 设置DocumentRoot指定目录的属性
Directory /var/www/html # 网站容器开始标识
Options Indexes FollowSymLinks # 找不到主页时链接到网站目录以外如测试页面
AllowOverride None # 对网站设置特殊属性:none不设置特殊属性,all允许
Require all granted # granted表示允许所有人访问denied表示拒绝所有人访问
/Directory # 容器结束
DirectoryIndex index.html # 定义主页文件会自动访问该文件。二、访问控制
1.准备测试页面
[rootqfedu.com ~]# echo test1 /var/www/html/index.html #编写测试文件2.访问控制测试
可以直接编辑apache主配置文件
1.默认允许所有主机访问
[rootqfedu.com ~]# vim /etc/httpd/conf/httpd.conf[rootqfedu.com ~]# systemctl restart httpd2.只拒绝一部分客户端访问:
[rootqfedu.com ~]# vim /etc/httpd/conf/httpd.conf访问网站服务器反回的状态码:403 没有权限访问
200表示访问网站成功[rootqfedu.com ~]# systemctl restart httpd[roottest ~]# curl -I http://192.168.153.144 #用另外一台机器测试访问成功
HTTP/1.1 200 OK
Date: Thu, 06 Aug 2020 20:40:37 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Thu, 06 Aug 2020 20:12:02 GMT
ETag: 6-5ac3b1a02ac4f
Accept-Ranges: bytes
Content-Length: 6
Content-Type: text/html; charsetUTF-8在Linux中curl是一个利用URL规则在命令行下工作的文件传输工具它支持文件的上传和下载是综合传输工具习惯称url为下载工具。
-o指定下载路径
-I:查看服务器的响应信息3.拒绝所有人
[rootqfedu.com ~]# vim /etc/httpd/conf/httpd.conf[rootqfedu.com ~]# systemctl restart httpd[roottest ~]# curl -I http://192.168.153.144
HTTP/1.1 403 Forbidden
Date: Thu, 06 Aug 2020 20:38:00 GMT
Server: Apache/2.4.6 (CentOS)
Content-Type: text/html; charsetiso-8859-1修改默认网站发布目录
[rootqfedu.com ~]# vim /etc/httpd/conf/httpd.conf
119 DocumentRoot /www # 修改网站根目录为/www
131 Directory /www # 把这个也对应的修改为/www[rootqfedu.com ~]# mkdir /www #创建定义的网站发布目录
[rootqfedu.com ~]# echo 这是新修改的网站根目录/www /www/index.html #创建测试页面
[rootqfedu.com ~]# systemctl restart httpd #重启服务三、虚拟主机
虚拟主机:将多个网站放在一台服务器上。web服务器都可以实现。
三种:基于域名 基于端口 基于Ip1.基于域名
[rootqfedu.com ~]# cd /etc/httpd/conf.d/
[rootqfedu.com conf.d]# vim test.conf #创建配置文件
VirtualHost *:80 #指定虚拟主机端口*代表监听本机所有ip也可以指定ip
DocumentRoot /soso #指定发布网站目录自己定义
ServerName www.soso666.com #指定域名可以自己定义
Directory /soso/AllowOverride None #设置目录的特性不设置目录的特性Require all granted #允许所有人访问
/Directory
/VirtualHostVirtualHost *:80
DocumentRoot /soho
ServerName test.soso666.com
Directory /soho/AllowOverride NoneRequire all granted
/Directory
/VirtualHost
[rootqfedu.com ~]# mkdir /soso #创建发布目录
[rootqfedu.com ~]# mkdir /soho
[rootqfedu.com ~]# echo qianfen /soso/index.html #创建测试页面
[rootqfedu.com ~]# echo qfedu /soho/index.html
[rootqfedu.com ~]# systemctl restart httpd配置域名解析:
在wind电脑上面打开C:\Windows\System32\drivers\etc\hosts文件。可以用管理员身份打开测试访问 基于端口
[rootqfedu.com ~]# vim /etc/httpd/conf/httpd.conf ---添加2.基于端口
[rootqfedu.com ~]# vim /etc/httpd/conf.d/test.conf
VirtualHost *:80DocumentRoot /sosoServerName www.soso666.com
Directory /soso/AllowOverride NoneRequire all granted
/Directory
/VirtualHostVirtualHost *:81 #修改端口DocumentRoot /sohoServerName test.soso666.com
Directory /soho/AllowOverride NoneRequire all granted
/Directory
/VirtualHost
[rootqfedu.com ~]# systemctl restart httpd
注意域名解析并没有变访问www.soso666.com 访问: test.soso666.com:81 3.基于IP
[rootqfedu.com ~]# ifconfig ens33:0 192.168.153.123 #添加一个临时ip
[rootqfedu.com ~]# vim /etc/httpd/conf.d/test.conf
VirtualHost 192.168.153.144:80 #指定ipDocumentRoot /soso#ServerName www.soso666.com
Directory /soso/AllowOverride NoneRequire all granted
/Directory
/VirtualHostVirtualHost 192.168.153.123:80 #指定ipDocumentRoot /soho#ServerName test.soso666.com
Directory /soho/AllowOverride NoneRequire all granted
/Directory
/VirtualHost
[rootqfedu.com ~]# systemctl restart httpd#取消添加的ip地址
#ifconfig ens33:0 192.168.153.123 down可以配置域名解析也可以不用配域名解析 Nginx 服务的搭建与配置
Nginx介绍
Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件IMAP/POP3代理服务器由俄罗斯的程序设计师Igor Sysoev所开发其特点是占有内存少并发能力强。事实上nginx的并发能力确实在同类型的网页服务器中表现较好。
安装 Nginx
1.2Nginx基本使用
获取Nginx
Nginx的官方主页 http://nginx.org关闭防火墙关闭selinux
[rootqfedu.com ~]# systemctl stop firewalld #关闭防火墙
[rootqfedu.com ~]# systemctl disable firewalld #开机关闭防火墙
[rootqfedu.com ~]# setenforce 0 #临时关闭selinux
[rootqfedu.com ~]# getenforce #查看selinux状态Nginx安装:
Yum方式
[rootqfedu.com ~]# cd /etc/yum.repos.d/
[rootqfedu.com yum.repos.d]# vi nginx.repo #编写nginx的yum源
[nginx]
namenginx
baseurlhttp://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck0
enabled1
[rootqfedu.com yum.repos.d]# yum clean all
[rootqfedu.com yum.repos.d]# yum makecache
[rootqfedu.com ~]# yum install -y nginx #安装nginx[rootqfedu.com ~]# systemctl start nginx #启动
[rootqfedu.com ~]# systemctl restart nginx #重启
[rootqfedu.com ~]# systemctl enable nginx #开机启动
[rootqfedu.com ~]# systemctl stop nginx #关闭1.查看nginx状态
[rootqfedu.com ~]# ps aux | grep nginx
root 3927 0.0 0.0 46384 968 ? Ss 18:46 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 3928 0.0 0.1 46792 1932 ? S 18:46 0:00 nginx: worker process
root 3932 0.0 0.0 112660 968 pts/1 R 18:47 0:00 grep --colorauto nginx
2.查看nginx端口
[rootqfedu.com ~]# netstat -lntp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3927/nginx: master
#注意nginx默认端口为80
3.测试主页是否可以访问
[rootqfedu.com ~]# curl -I http://127.0.0.1
HTTP/1.1 200 OK
Server: nginx/1.16.1
Date: Sat, 16 Nov 2019 10:49:48 GMT
Content-Type: text/html
Content-Length: 635
Last-Modified: Fri, 11 Oct 2019 06:45:33 GMT
Connection: keep-alive
ETag: 5da0250d-27b
Accept-Ranges: bytes常见的组合方式
LNMP (Linux Nginx MySQL/Mariadb PHP) #php-fpm进程这个组合是公司用的最多的组合
LAMP (Linux Apache MySQL/Mariadb PHP)