linux下Apache的部署

一、linux下的网络服务

1.http 浏览器默认访问端口是80

2.默认访问目录是/var/www/html 的index.html超文本编辑语言 编辑:hello 在阿帕奇可以看到

3.测试: 配置ip,配置yum源
4.下载服务:

yum install httpd-manual 

yum install httpd -y 

systemctl restart httpd 

5.火墙允许(firewall-config)http、https

修改默认端口:

getenforce为Permissive的情况下:

vim /etc/httpd/conf/httpd.conf 
编辑:
42 Listen 8080

(修改完后退出保存重启)

firewall-config 添加8080和6666的接口做实验

也可以使用命令 semanage port -l | grep http查看允许端口

setenforce为 1的情况下:

使用命令添加允许端口:

semanage port -a -t http_port_t -p tcp 6666 

systemctl restart httpd 

二、修改默认发布文件

cd /var/www/html vim westos.html 
编辑:

westos linux

修改配置文件:
 

vim /etc/httpd/conf/httpd.conf 

编辑 :

164 DirectoryIndex index.html 改成:

164 DirectoryIndex westos.html index.html 

systemctl restart httpd

三、修改默认目录

mkdir /westos/web/html -p 

vim /westos/web/html/westos.html 

编辑:

/westos/web/html's page
修改配置文件:

vim /etc/httpd/conf/httpd.conf

119 DocumentRoot "/var/www/html" 改成:

119 #DocumentRoot "/var/www/html" 

120 DocumentRoot "/westos/web/html" 

121 

122 Require all granted 

修改安全上下文:
 

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

restorecon -RvvF /westos/ 

systemctl restart httpd 

四、apache的虚拟主机

在使用浏览器的主机上:
 

vim /etc/hosts 

编辑:172.25.254.130 www.westos.com news.westos.com music.westos.com

在desktop虚拟机上:

恢复httpd文件:rm -rf /etc/httpd/conf/httpd.conf

重新下载:yum reinstall httpd -y

cd /var/www 

mkdir westos.com/news/html -p 

mkdir westos.com/music/html -p 

vim westos.com/news/html/index.html 

编辑:news's page

vim westos.com/music/html/index.html 

编辑:music's page

cd /etc/httpd/conf.d
 

vim a_default.conf 

编辑: 

DocumentRoot /var/www/html CustomLog logs/default.log combined 

vim news.conf 

编辑: 

ServerName news.westos.com DocumentRoot /var/www/westos.com/news/html CustomLog logs/news.log combined Require all granted

vim music.conf 

编辑: ServerName music.westos.com DocumentRoot /var/www/westos.com/music/html CustomLog logs/music.log combined Require all granted 

systemctl restart httpd 

五、访问控制

1.基于ip控制访问

cd /etc/httpd/conf.d

vim a_default.conf

编辑:

Order Deny,Allow

Allow from 172.25.254.20

Deny from 172.25.254.30

退出保存重启服务

2.基于用户控制访问
 

htpasswd -cm http_userlist admin 

htpasswd -m http_userlist admin1 

cat http_userlist有两个登陆用户 

重新建立用户的时候去掉c ,即htpasswd -m http_userlist admin 
vim a_default.conf(注释掉上面的几行)

编辑:

AuthUserFile /etc/httpd/conf.d/http_userlist AuthName "Please input username and password !!" 
AuthType basic # Require user admin  ##允许admin这一个用户登录
或者AuthType basic Require valid-user ##允许所有用户登陆 

退出保存重启服务

清楚浏览器缓存:ctrl+shift+delete

六、Apache支持的语言

1.html
2.php
 

vim /var/www/html/index.php

编辑:

<?php
    phpinfo();
>
yum install php -y
systemctl restart httpd


在浏览器上测试:
172.25.254.130/index.php

3.cgi
 

mkdir -p /var/www/html/cgi
semanager fcontent -a -t httpd_sys_script_exec_t '/var/www/html/cgi(/.*)?'
restorecon -RvvF /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
编辑:

#!/usr/bin/perl
     print "Content-type: text/html\n\n";
     print `date`;


chmod +x /var/www/html/cgi/index.cgi


./var/www/html/cgi/index.cgi  ##执行下脚本确保脚本运行正常

vim a_default.conf
17<Directory "/var/www/html/cgi">
18    Options +ExecCGI
19    AddHandler cgi-script .cgi
20</Directory>


七、加密访问https

先安装两个服务:

yum install mod_ssl -y
yum install crypto-utils -y


重启服务

genkey www.westos.com(进入设置图形界面)


等待的时间在虚拟机界面打开shell随便敲

vim /etc/httpd/conf.d/ssl.conf
编辑:
101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
109 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key

重启服务

八、设定https虚拟主机并设定网页重写

cd /var/www/westos.com
mkdir login
mkdir login/html
vim login/html/index.html(不知道的钥匙可以在/etc/httpd/conf.d/ssl.conf找)
vim login.conf
  1 <VirtualHost *:443>
  2         ServerName login.westos.com
  3         DocumentRoot /var/www/html/virtual/login.westos.com/html
  4         CustomLog "logs/login.logs" combined
  5         SSLEngine on
  6         SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
  7         SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
  8 </VirtualHost>
  9 <Directory "/var/www/html/virtual/login.westos.com/html">
 10         Require all granted
 11 </Directory>
 12 <VirtualHost *:80>
 13         ServerName login.westos.com
 14         RewriteEngine On
 15         RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
 16 </VirtualHost>
systemctl restart httpd

^(/.*)$      ##客户在浏览器地址输入的所有字符
https://     ##强制客户加密访问
%{HTTP_HOST} ##客户请求主机
$1         ##“$1”标示
[redirect=301
301永久
302临时
 

九、正向代理和反向代理
正向代理:客户代理
反向代理:企业控制

1.正向代理
server作为代理
desktop去“翻墙”

server:

vim /etc/sysconfig/network-scripts/ifcfg-eth0
编辑:NAME=eth0
     ONBOOT=yes
     BOOTPROTO=none
     IPADDR=172.25.254.230
     NETMASK=255.255.255.0
     GATEWAY=172.25.254.250(能上网的一个ip地址)
     DNS1=114.114.114.114


关闭火墙;systemctl stop firewalld
配置yum源:cd /etc/yum.repos.d/
          ls查看打开文件:
         

vim rhel_dvd.repo
            编辑:baseurl = http://172.25.254.250/rhel7.0/x86_64/dvd


修改名字:hostnamectl set-hostname squid.westos.com
下载yum stall squid -y

vim /etc/squid/squid.conf
编辑: 56 http_access allow all
      59 http_port 3128(不用改,注意下就行)
      62 cache_dir ufs /var/spool/squid 100 16 256 (打开注释)


ls /var/spool/squid/看不到内容
systemctl start squid
ls /var/spool/squid/能看到内容了

在desktop端(apache-server)
在浏览器上搜索www.baidu.com
搜不到
打开浏览器的edit里的preferences-->neywork-->settiongs-->点击manual..设置http proxy为172.25.254.230 prot是3128点击use this
ok

重新在浏览器上搜索www.baidu.conm可以看到网页内容


2.反向代理
cdn加速(content delivery network)
1.server(squid)

vim /etc/squid/squid.conf
编辑:56 http_access allow all
     59 http_port 80 vhost vport
     60 cache_peer 172.25.254.120 parent 80 0 proxy-only name=web1 round-robin weight=2(刷新两次切换)
     61 cache_peer 172.25.254.130 parent 80 0 proxy-only name=web2 round-robin
     62 cache_peer_domain web1 web2 www.westos.com
systemctl restart squid 


2.真机:
vim /etc/hosts
更改解析ip是172.25.254.230
确保130的httpd服务开启,确保230没有httpd服务(使用rpm -qa | grep httpd查看是否有httpd服务,如果有使用yum remove httpd卸载服务然后重启服务systemctl restart squid)
测试:在浏览器搜索www.westos.com刷新会有两种结果轮巡

十、使用Apache创建论坛

vim /etc/httpd/conf.d

cp music.conf bbs.conf

vim bbs.conf把所有的music替换成bbs

mkdir  /var/www/westos.com/bbs/html -p

将下载好的论坛压缩包复制到这个路径下:/var/www/westos.com/bbs/html/

解压后,使用ls查看:

cd  readme/

less read.text可以查看到搭建论坛的步骤和要求。

cd /var/www/westos.com/bbs/html/upload

chmod -R 777 config

chmod -R 777 data

在使用浏览器访问的主机上:

vim /etc/hosts

编辑:172.25.254.130 bbs.westos.com

setenforce 0

setsebool -P httpd_anon_write on

setsebool -P httpd_sys_script_anon_write on

chmod 777 uc_client uc_server -R

上面的配置是不够的,因为Apache现在读不懂我们在讲什么,所以要下载相关服务:

yum install mariadb-server -y

systemctl start mariadb

systemctl enable mariadb

打开配置文件:

vim /etc/my.cnf

编辑:

10 skip-networking=1

systemctl restart mariadb

进行安全初始化:

mysql_secure_installation

这个要使用之前建立数据库的密码,如果忘记可以重新建立密码

yum install php-mysql.x86_64 -y

systemctl restart httpd

完成上面的操作后在浏览器搜索bbs.westos.com/upload 就可以安装登录自己的论坛了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值