建站服务器
######apache web服务############
本单元涵盖的主题:
* apache基本配置
* 虚拟主机配置
* https配置
* 集成动态内容
########apache基本配置########
apache主配置文件:/etc/httpd/conf/httpd.conf
serverroot"/etc/httpd"用于指定apache的运行目录listen80监听端口userapache运行apache程序的用户和组groupapacheserveradminroot@localhost管理员邮箱documentroot"/var/www/html"网页文件的存放目录<directory"/var/www/html"><directory>语句块自定义目录权限requireallgranted</directory>errorlog"logs/error_log"错误日志存放位置adddefaultcharsetutf-8默认支持的语言includeoptionalconf.d/*.conf加载其它配置文件directoryindexindex.html默认主页名称
########apache的安装#######
yum install httpd -y 安装apache软件包
systemctl start httpd 启动apache服务
systemctl stop firewalld
systemctl enable httpd
systemctl disable firewalld
netstat -antlpe | grep httpd##查看监听端口
#####apache的基本配置#######
1.apache的默认发布文件
index.html
2.apache的配置文件
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
3.apache的默认发布目录
/var/www/html
默认发布文件
4.apache的默认端口
80
######修改apache的基本配置########
1.修改默认发布文件
vim /etc/httpd/conf/httpd.conf
164directoryindexwestos.htmlindex.html##默认主页名称
systemctl restart httpd
2.修改默认发布目录cdn0pxpfu346.png/>
###当selinux是disable状态时
vim /etc/httpd/conf/httpd.conf
120documentroot"/westos/www/html"##网页文件的存放目录121<directory"/westos/www/html">##语句块自定义目录权限122requireallgranted123</directory>systemctl restart httpd
##当selinux是enforcing状态时
semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'##配置安全上下文
restorecon -rvvf /westos
测试:172.25.254.162
3.apache的访问控制
vim /etc/httpd/conf/httpd.conf
<directory"/var/www/html/admin">##允许所有人访问admin目录但拒绝62主机orderallow,denyallowfromalldenyfrom172.25.254.62</directory>
<directory"/var/www/html/admin">##只允许62主机访问admin目录orderdeny,allowallowfrom172.25.254.62denyfromall</directory>
systemctl restart httpd
测试:172.25.254.162/admin/
#####设定用户的访问########
#####用两个账户创建apache密码文件
htpasswd -cm /etc/httpd/accessuser admin##建立用户认证文件并建立用户admin设置密码123
htpasswd -m /etc/httpd/accessuser cui##建立认证用户cui,密码123
vim /etc/httpd/conf/httpd.conf ##配置基于用户的身份验证
<directory"/var/www/html/admin">authuserfile/etc/httpd/accessuser##用户认证文件authname"pleaseinputyournameandpassword!!"##用户认证提示信息authtypebasic##认证类型requirevalid-user##认证用户,认证文件中所有的用户都可以通过或[requireuseradmin]##只允许认证文件中的admin用户访问,二写一</directory>systemctl restart httpd ##重启apache服务,并使用web浏览器测试访问,在弹出的对话框中输入上述用户名和密码。
测试:172.25.254.162/admin/
4.apache 语言支持
html语言支持
php语言支持
yum install php -y##安装php服务
vim /var/www/html/index.php ##写php测试
<?phpphpinfo()?>systemctl restart httpd
测试:172.25.254.162
cgi语言支持
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi ##默认发布文件主页内容
#!/usr/bin/perlprint"content-type:text/html\\\\n\\\\n";print`date`;
vim /etc/httpd/conf/httpd.conf
<directory"/var/www/html/cgi">##网页文件目录options execcgiaddhandlercgi-script.cgi</directory>directoryindexindex.cgiindex.html##默认访问主页名称systemctl restart httpd
chmod x index.cgi##给文件添加执行权限
测试:
172.25.254.136/cgi/
#####apache的虚拟主机#####
1.定义
可以让我们的一台apache服务器在被访问不同域名的时候显示不同的主页
虚拟主机允许您从一个httpd服务器同时为多个网站提供服务。在本节中,我们将了解基于名称的虚拟主机其中多个主机名都指向同一个ip地址,但是web服务器根据用于到达站点的主机名提供具有不同内容的不同网站。
2.建立测试页
##########建立网页发布目录#######
mkdir /var/www/virtual/money.westos.com/html -p
mkdir /var/www/virtual/news.westos.com/html -p
echo "<h2>news.westos.coms's page</h2>">/var/www/virtual/news.westos.com/html/index.html
echo "<h2>money.westos.coms's page</h2>">/var/www/virtual/money.westos.com/html/index.html
3.配置##创建虚拟主机配置文件
vim /etc/httpd/conf.d/default.conf ##未指定域名的访问都访问default
###这是定义虚拟主机的块
<virtualhost_default_:80>##虚拟主机开启的端口documentroot"/var/www/html"##虚拟主机默
云服务器怎么搭建铁锈战争广州云媒体服务器价格maya工具栏怎么还原 maya工具栏重置方法中文cn域名云服务器租用学生特惠nodejs、npm、nvm三者有什么关系?万达电商前CEO董策:一天自我审视8次服务器如何维护