ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux中Apache的管理及优化

2021-08-01 14:06:30  阅读:113  来源: 互联网

标签:httpd www westos var html Linux Apache org 优化


一、Apache的作用

在web被访问时通常使用http://的方式
http://            ##超文本传输协议

http://    超文本传输协议提供软件:
Apache
nginx
stgw
jfe
Tengine

二、Apache的安装以及启用

dnf install httpd.x86_64  -y    ##安装httpd

firewall-cmd --permanent --add-service=http  ##将http服务加到防火墙的服务名单中

firewall-cmd --permanent --add-service=https ##将https服务加到防火墙的服务名单中

firewall-cmd --reload   ##重启防火墙,让刚才的操作生效

systemctl enable --now httpd ##启动httpd服务

vim /var/www/html/index.html ##编辑文件

三、Apache的基本配置
配置文件:/etc/httpd/conf/httpd.conf
端口设置:
Listen:8080

默认发布文件:

vim /var/www/html/westos.html##编辑文件

168行左右
<IfModule dir_module>
DirectoryIndex westos.html index.html

firefox查询:172.25.254.137

默认发布目录:
mkdir /westos_apache
vim /westos_apache/index.html

semanage fcontext -a -t httpd_sys_content_t '/westos_apache(/.*)?'

vim /etc/httpd/conf/httpd.conf :
123行左右
#DocumentRoot "/var/www/html"
DocumentRoot "/westos_apache"
<Directory "/westos_apache">
           Require all granted
</Directory>

firefox查询:172.25.254.137

四、Apache访问控制
1)ip限制:
vim /etc/httpd/conf/httpd.conf :
DocumentRoot "/var/www/html"
#DocumentRoot "/westos_apache"
<Directory "/var/www/html/westos">
           Order Deny,Allow
           Deny from all
           Allow from 172.25.254.137
</Directory>
systemctl restart httpd

2)用户限制:
cd /etc/httpd/
mkdir westos ##建立查看文件
vim /westos/index.html
htpasswd -cm .htpasswd admin ##建立用户(环境)

vim /etc/httpd/conf/httpd.conf:
<Directory "/var/www/html/westos">
           AuthUserFile  (用户建立环境在那就指向那里)
           AuthName "Please input username and password"
           AuthType basic
#           Require user  admin
           Require valid-user

systemctl restart httpd

五、Apache的虚拟主机
建立域名、相关文件
mkdir -p /var/www/vhost/westos.org/{news,music,yifan.org}
echo news.westos.org> /var/www/vhost/westos.org/news/index.html
echo music.westos.org> /var/www/vhost/westos.org/music/index.html
echo yifan.westos.org> /var/www/vhost/westos.org/yifan/index.html
echo yifan.org.westos.org> /var/www/vhost/westos.org/yifan.org/index.html

编辑配置文件(服务器)
<VirtualHost _default_:80>
        DocumentRoot /var/www/html
        CustomLog logs/default.log combined
</VirtualHost>

<VirtualHost *:80>
        ServerName music.westos.org
        DocumentRoot /var/www/vhost/westos.org/music
        CustomLog logs/music.log combined
</VirtualHost>

<VirtualHost *:80>
        ServerName news.westos.org
        DocumentRoot /var/www/vhost/westos.org/news
        CustomLog logs/news.log combined
</VirtualHost>

<VirtualHost *:80>
        ServerName yifan.org.westos.org
        DocumentRoot /var/www/vhost/westos.org/'yifan'
        CustomLog logs/yifan.org.log combined
</VirtualHost>

手动解析域名(浏览器在哪里就在那里写)
vim /etc/hosts:
172.25.254.137 www.westos.org music.westos.org news.westos.org yifan.org.westos.org

测试:
firefox:www.westos.org | music.westos.org | news.westos.org | yifan.org.westos.org(任意一个)

六、Apache的语言支持
#php#
vim /var/www/html/index.php
<?php
    phpinfo();
?>

dnf install php -y
systemctl restart httpd
firefox http://192.168.0.11/index.php

#cgi#
mkdir /var/www/html/cgidir
vim /var/www/html/cgidir/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;

systemctl restart httpd


vim /etc/httpd/conf.d/vhost.conf

<Directory "/var/www/html/cgidir">
    Options +ExecCGI
    AddHandler cgi-script .cgi
</Directory>

firefox http://192.168.0.11/cgidir/index.cgi

#wsgi#
书写wsgi的测试文件
vim /var/www/html/wsgi/index.wsgi
def application(env, westos):
    westos('200 ok',[('Content-Type', 'text/html')])
    return [b'hello  westos ahhahahahah!']

dnf install python3-mod_wsgi
systemctl restart httpd

vim /etc/httpd/conf.d/vhost
<VirtualHost *:80>
    ServerName wsgi.westos.org
    WSGIScriptAlias / /var/www/html/wsgi/index.wsgi
</VirtualHost>

七、Apache的加密访问

mkdir /etc/httpd/tls ##建立目录用来存放锁和钥匙

openssl req --newkey rsa:2048 -nodes -sha256 -keyout /etc/httpd/tls/westos.org.key -x509 -days 365 -out /etc/httpd/tls/westos.org.crt   ##建立锁和钥匙

vim /etc/httpd/conf.d/vhost.conf

标签:httpd,www,westos,var,html,Linux,Apache,org,优化
来源: https://blog.csdn.net/weixin_45205924/article/details/119293611

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有