web服务器安装与基本操作(apache)

序号主机名称系统备注
1

192.168.3.81

192.168.8.81

stu1

stua

rockylinux8.6最小化安装,关闭selinux
2

192.168.3.82

192.168.8.82

stu2

stub

rockylinux8.6最小化安装,关闭selinux

1、安装

dnf install -y httpd vim net-tools bash-completion
echo 'my first website'  > /var/www/html/index.html
systemctl enable  --now httpd
netstat -anplut| grep httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --reload

bash-completion命令补全,需重新登陆

2、基于域名的虚拟主机

虚拟主机模板目录     /usr/share/doc/httpd/httpd-vhosts.conf

192.168.3.81:

mkdir /var/www/web1
mkdir /var/www/web2
echo 'my web1' > /var/www/web1/index.html
echo 'my web2' > /var/www/web2/index.html



vim /etc/httpd/conf.d/web.conf

<VirtualHost *:80>
    ServerAdmin web1@example.com
    DocumentRoot "/var/www/web1"
    ServerName www.web1.com
    ServerAlias web1.com
    ErrorLog "/var/log/httpd/web1.com-error_log"
    CustomLog "/var/log/httpd/web1.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin web2@example.com
    DocumentRoot "/var/www/web2"
    ServerName www.web2.com
    ServerAlias web2.com
    ErrorLog "/var/log/httpd/web2.com-error_log"
    CustomLog "/var/log/httpd/web2.com-access_log" common
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin web@example.com
    DocumentRoot "/var/www/html"
    ServerName www.web.com
    ServerAlias web.com
    ErrorLog "/var/log/httpd/web.com-error_log"
    CustomLog "/var/log/httpd/web.com-access_log" common
</VirtualHost>


systemctl restart httpd

192.168.3.82:

vi /etc/hosts
192.168.3.81  stu1 www.web1.com  www.web2.com www.web.com

3、基于IP的虚拟主机

192.168.3.81

vim /etc/httpd/conf.d/web.conf

<VirtualHost 192.168.3.81:80>
    ServerAdmin web1@example.com
    DocumentRoot "/var/www/web1"
    ServerName www.web1.com
    ServerAlias web1.com
    ErrorLog "/var/log/httpd/web1.com-error_log"
    CustomLog "/var/log/httpd/web1.com-access_log" common
</VirtualHost>

<VirtualHost 192.168.8.81:80>
    ServerAdmin web2@example.com
    DocumentRoot "/var/www/web2"
    ServerName www.web2.com
    ServerAlias web2.com
    ErrorLog "/var/log/httpd/web2.com-error_log"
    CustomLog "/var/log/httpd/web2.com-access_log" common
</VirtualHost>


systemctl restart httpd

 192.168.3.82:

 4、基于端口的虚拟主机

192.168.3.81:

firewall-cmd --permanent --add-port=88/tcp
firewall-cmd --permanent --add-port=81/tcp
firewall-cmd --reload


vim /etc/httpd/conf/httpd.conf  (增加)
Listen 88
Listen 81

vim /etc/httpd/conf.d/web.conf
<VirtualHost *:81>
    ServerAdmin web@example.com
    DocumentRoot "/var/www/web1"
    ServerName www.web.com
    ServerAlias web.com
    ErrorLog "/var/log/httpd/web1.com-error_log"
    CustomLog "/var/log/httpd/web1.com-access_log" common
</VirtualHost>

<VirtualHost *:88>
    ServerAdmin web@example.com
    DocumentRoot "/var/www/web2"
    ServerName www.web.com
    ServerAlias web.com
    ErrorLog "/var/log/httpd/web2.com-error_log"
    CustomLog "/var/log/httpd/web2.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin web@example.com
    DocumentRoot "/var/www/html"
    ServerName www.web.com
    ServerAlias web.com
    ErrorLog "/var/log/httpd/web.com-error_log"
    CustomLog "/var/log/httpd/web.com-access_log" common
</VirtualHost>

5、拒绝访问

192.168.3.81:

vim /etc/httpd/conf.d/web.conf
<VirtualHost *:80>
    ServerAdmin web1@example.com
    DocumentRoot "/var/www/web1"
    ServerName www.web1.com
    ServerAlias web1.com
    ErrorLog "/var/log/httpd/web1.com-error_log"
    CustomLog "/var/log/httpd/web1.com-access_log" common

<Directory "/var/www/web1">
    order allow,deny
    allow from all
    deny from 192.168.3
</Directory>

</VirtualHost>

<VirtualHost *:80>
    ServerAdmin web2@example.com
    DocumentRoot "/var/www/web2"
    ServerName www.web2.com
    ServerAlias web2.com
    ErrorLog "/var/log/httpd/web2.com-error_log"
    CustomLog "/var/log/httpd/web2.com-access_log" common

<Directory "/var/www/web2">
    order deny,allow
    allow from all
    deny from 192.168.3.82
</Directory>

</VirtualHost>


<VirtualHost *:80>
    ServerAdmin web@example.com
    DocumentRoot "/var/www/html"
    ServerName www.web.com
    ServerAlias web.com
    ErrorLog "/var/log/httpd/web.com-error_log"
    CustomLog "/var/log/httpd/web.com-access_log" common

<Directory "/var/www/html">
    order allow,deny
    deny from 192.168.3.82
    allow from all
</Directory>

</VirtualHost>

systemctl restart httpd

192.168.3.82:

 注:网段为192.168.3

Order deny,allow
 allow from all
 deny from 192.168.3.82
 #全部都可以访问
-------------------------------
Order allow,deny
 deny from 192.168.3.82
 allow from all
 #只有192.168.3.82不能访问
-------------------------------
Order allow,deny
 allow from all
 deny from 192.168.3.82
 #只有192.168.3.82不能访问
-------------------------------
Order allow,deny
 deny from all
 allow from 192.168.3
 #全部都不能访问
-------------------------------
Order allow,deny
 allow from 192.168.3
 deny from all
 #全部都不能访问 
-------------------------------

6、用户名密码访问网站

192.168.3.81

<VirtualHost *:80>
    ServerAdmin web@example.com
    DocumentRoot "/var/www/html"
    ServerName 192.168.3.81
    ServerAlias web.com
    ErrorLog "/var/log/httpd/web.com-error_log"
    CustomLog "/var/log/httpd/web.com-access_log" common

<Directory "/var/www/html">
    AllowOverride None
    authtype basic
    authname "my website"
    authuserfile /etc/httpd/conf/passwd.secret
    require valid-user
</Directory>

</VirtualHost>
htpasswd -cm /etc/httpd/conf/passwd.secret web

systemctl restart httpd

windows系统访问

http://192.168.3.81

​​​​​​​ 




 

实战Nginx:取代Apache的高性能Web服务器 作者: 张宴 出版社: 电子工业出版社 出版年: 2010年2月 内容简介   Nginx (“engine x”) 是俄罗斯人Igor Sysoev编写的一款高性能HTTP 和反向代理服务器。Nginx选择了epoll和kqueue作为网络I/O模型,在高连接并发的情况下,Nginx是Apache服务器不错的替代品,它能够支持高达50 000个并发连接数的响应,运行稳定,且内存、CPU等系统资源消耗非常低。   本书主要分为4个部分,第1部分为基础篇,介绍了Nginx服务器安装配置方法;第2部分为进阶篇,重点介绍了Nginx的配置优化方法、NginxPHP/Ruby/Python/JSP/Perl/Memcached的结合配置方法、Nginx HTTP反向代理负载均衡的配置优化、Nginx模块开发等,最后还分析了新浪的开源软件项目──基于Nginx的NCache网页缓存系统;第3部分为实战篇,分析了Nginx在国内知名网站(如新浪播客、搜狐博客等)中的应用案例;第4部分为模块篇,对Nginx的基本模块和第三方模块进行了集中介绍。   本书是为对配置管理Nginx服务器感兴趣的读者准备的,适用于以前没有接触过Nginx,或者对Nginx有一些了解并希望能够进一步深入学习的专业系统工程师、个人网站站长及Linux/Unix从业人员。   作者简介   张宴,就职于北京金山软件公司,金山游戏官方网站──逍遥网(xoyo.com)系统架构师,技术支持部平台组组长。曾在新浪网、赶集网等公司任系统工程师、系统架构师,工作内容主要涉及:服务器系统架构设计部署、系统运维调优、网络故障解决、网站后端以及接口类PHP程序开发、Unix开源软件二次开发、服务器监控系统开发、系统运维平台研发团队管理。 第1章 Nginx简介.pdf 第2章 Nginx服务器安装配置.pdf 第3章 Nginx的基本配置优化.pdf 第4章 NginxPHP(FastCGI)安装、配置优化.pdf 第5章 NginxJSP、ASP.NET、Perl的安装配置.pdf 第6章 Nginx HTTP负载均衡和反向代理的配置优化.pdf 第7章 Nginx的Rewrite规则实例.pdf 第8章 Nginx模块开发.pdf 第9章 Nginx的Web缓存服务新浪网的开源NCACHE模块.pdf 第10章 Nginx在国内知名网站中的应用案例.pdf 第11章 Nginx的非典型应用实例.pdf 第12章 Nginx的核心模块.pdf 第13章 Nginx的标准HTTP模块.pdf 第14章 Nginx的其他HTTP模块.pdf 第15章 Nginx的邮件模块.pdf
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值