CentOS7/RedHat7的Apache配置介绍

这里我们介绍yum安装httpd yum install -y httpd
*************

[root@100 ~]# systemctl restart httpd
[root@100 ~]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@100 ~]# vim /etc/httpd/

安装的版本介绍
image.png
备份一下配置文件
[root@100 ~]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak
******
需要了解的知识块
1、了解Apache的基本配置
2、配置动态页面:CGI、wsgi、ssl
3、配置一个虚拟主机
4、配置https

1、了解Apache的基本配置
编辑Apache的配置文件httpd.conf 路径在/etc/httpd/conf/httpd.conf
默认的配置文件路径ServerRoot "/etc/httpd"
默认监听的端口Listen 80
模块存放路径[root@100 ~]# ls /etc/httpd/conf.modules.d/
所属者和所属组
User apache
Group apache
默认安装的时候他会创建一个不可登录系统的用户
apache❌48:48:Apache:/usr/share/httpd:/sbin/nologin
默认的管理员邮箱是ServerAdmin root@localhost
站点配置#ServerName www.example.com:80 默认是禁用的
站点的目录设置
<Directory "/var/www"> ------------<Directory "/var/www/html">
AllowOverride None ------------------Options Indexes FollowSymLinks
# Allow open access: -----------------AllowOverride None
Require all granted --------------------Require all granted
----------------------------
站点设置项:
(Options 里的indexes是开启开启索引,FollowSymLinks是允许链接文件--需要修改上下文chcon -R --reference=/var/www/html /new)

(AllowOverride None 是否允许单前目录下的一个隐藏文件.htaccess里的配置覆盖当前httpd.conf
的里设置--用于http的认证
在网页的根目录下创建一个
[root@100 html]# cat /var/www/html/.htaccess
AuthType Basic
AuthName haha
AuthUserfile /etc/httpd/conf/.htpasswd
Require user tom

/etc/httpd/conf/.htpasswd这个文件需要用
[root@100 html]# htpasswd -cm /etc/httpd/conf/.htpasswd tom ##-cm 创建用MD5
加密
New password:
Re-type new password:
Adding password for user tom
[root@100 html]#
修改后的AllowOverride AuthConfig 接下来访问就要提示用户密码

(Require all granted 允许所有
Require all denied 拒绝所有
Require ip 192.168.1.1 允许这地址访问
Require ip 192.168.1.0/24 这个端地址可以访问
Require local
Require ip 192.168.1.1 192.168.2.2 这俩个地址可以访问


站点的文档目录DocumentRoot "/var/www/html"
设置文件的权限
<Files ".ht*">
Require all denied

错误日志ErrorLog "logs/error_log"

Alias 设置别名 # Alias /webpath /full/filesystem/path默认是禁用的--每设置一个目录就需要加一个
<Directory "/mnt/html">
AllowOverride None
# Allow open access:
Require all granted

2、配置动态页面:CGI、wsgi、ssl
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" 这是CGI的脚本路径
[root@100 cgi-bin]# pwd
/var/www/cgi-bin
[root@100 cgi-bin]# cat *

#!/usr/bin/perl
print "Content-Type: text/html; charset=UTF-8\n\n";
$time=localtime();
print "$time\n"
#!/bin/bash
echo "Content-Type: text/html; charset=UTF-8"
echo 
date +'%F %T'
hostname 

[root@100 cgi-bin]#
浏览器访问http://xxxxxxxxx/cgi-bin/aa.sh 实现的效果就是获取本地时间

wsgi是python实现的一种动态页面功能默认没有按照
[root@100 cgi-bin]# yum install -y mod_wsgi
在/etc/httpd/conf/httpd.conf配置文件里修改
253 ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
254
255
256
257 WSGIScriptAlias /wsgi-bin/ "/var/www/cgi-bin/"
浏览器访问测试http://xxxxxx/wsgi-bin/aa.wsgi 实现的效果就是显示本地时间
[root@100 wsgi-bin]# cat aa.wsgi

#!/usr/bin/env python
import time
def application (environ, start_response):
    a = time.ctime(time.time())
    response_body = 'This Dynamic WSGI Page Was Generated at: \n%s\n'%a
    status = '200 OK'
    response_headers = [('Content-Type', 'text/plain'),
               ('Content-Length', '1'),
               ('Content-Length',str(len(response_body)))]
    start_response(status, response_headers)
    return [response_body]

SSI 设置动态页面是需要在配置文件里设置
在站点目录这里添加includes

 Options Indexes FollowSymLinks Includes   ##include包含

ssi设置的页面默认是*.shtml
Vim /var/www/html/index.shtml


helloworld


       当前的用户是: <!--#exec cmd="whoami" -->
       当前的时间是:<!--#echo var="DATE_LOCAL" -->
       访问者的ip是:<!--#echo var="REMOTE_ADDR"-->
    

~
测试连接http://xxxxx/index.shtml
##调用刚才的cgi脚本

注意点:
站点根目录下的默认是访问index.html怎么把它设置成index.shtml呢?
就需要用到地址重写功能
在http的配置文件里追加
362 RewriteEngine on
363 RewriteRule ^/?$ /index.shtml [R]
他会使你的浏览器默认重定向站点的shtml里

3、虚拟主机的配置
默认http的配置文件在这里

# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf

这里我们写一个基于一个IP解析俩个不同站点的案例(基于主机名的虚拟主机)
image.png

这里复制一个模板文件

[root@100 ~]# cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf.d/vhosts.conf
[root@100 conf.d]# echo zzz > /var/www/html/index.html;echo cc /cc/index.html
[root@100 conf.d]# systemctl restart httpd
[root@100 conf.d]# cat vhosts.conf 
<VirtualHost *:80>
    DocumentRoot /cc
    ServerName www.cc.com
    ErrorLog "/var/log/httpd/www.cc.com-error_log"
    CustomLog "/var/log/httpd/dummy-www.cc.com.com-access_log" common
</VirtualHost>
<Directory "/cc">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<VirtualHost *:80>
    DocumentRoot /var/www/html
    ServerName www.zzz.com
    ErrorLog "/var/log/httpd/www.zzz.com-error_log"
    CustomLog "/var/log/httpd/dummy-www.zzz.com.com-access_log" common
</VirtualHost>
<Directory "/var/www/html">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
cho
[root@100 conf.d]# chcon -R --reference=/var/www/html /cc  #更改上下文

(如果是基于ip的虚拟主机只需修改你的dns解析即可)

基于端口的虚拟主机

[root@100 conf.d]# cat vhosts.conf 
<VirtualHost *:801>
    DocumentRoot /cc
    ServerName www.cc.com
    ErrorLog "/var/log/httpd/www.cc.com-error_log"
    CustomLog "/var/log/httpd/dummy-www.cc.com.com-access_log" common
</VirtualHost>
<Directory "/cc">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

<VirtualHost *:802>
    DocumentRoot /var/www/html
    ServerName www.zzz.com
    ErrorLog "/var/log/httpd/www.zzz.com-error_log"
    CustomLog "/var/log/httpd/dummy-www.zzz.com.com-access_log" common
</VirtualHost>
<Directory "/var/www/html">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
[root@100 conf.d]# cat /etc/httpd/conf/httpd.conf
#Listen 12.34.56.78:80
Listen 80
Listen 801
Listen 802

简书链接
有探讨的在下方留言
--END--

转载于:https://www.cnblogs.com/haozheyu/p/9920372.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 安装JDK CentOS 7 默认的 JDK 版本是 1.8,如果需要安装其他版本的 JDK,可以执行以下命令: a. 首先,下载对应版本的 JDK,这里下载的是 JDK 11: wget https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz b. 解压文件: tar -zxvf openjdk-11.0.1_linux-x64_bin.tar.gz c. 将解压后的文件夹移动到 /usr/local 目录下: sudo mv jdk-11.0.1 /usr/local/ d. 配置环境变量: sudo vim /etc/profile 在文件末尾添加以下内容: export JAVA_HOME=/usr/local/jdk-11.0.1 export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export PATH=$PATH:$JAVA_HOME/bin e. 使环境变量生效: source /etc/profile 2. 安装Jenkins a. 导入 Jenkins 的 GPG 密钥: sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key b. 创建 Jenkins 的 Yum 源: sudo vim /etc/yum.repos.d/jenkins.repo 添加以下内容: [jenkins] name=Jenkins stable baseurl=https://pkg.jenkins.io/redhat-stable gpgcheck=1 c. 安装 Jenkins: sudo yum install jenkins d. 启动 Jenkins: sudo systemctl start jenkins e. 开启 Jenkins 的自动启动: sudo systemctl enable jenkins f. 查看 Jenkins 的状态: sudo systemctl status jenkins 如果成功安装,会显示 active (running)。 g. 配置 Jenkins: 在浏览器中输入服务器的 IP 地址或域名,加上端口号 8080,如:http://192.168.1.100:8080/,打开 Jenkins 的 Web 界面。根据界面提示,输入初始密码,然后按照提示完成 Jenkins 的配置。 3. 配置 Jenkins 的 JDK 环境 a. 在 Jenkins 的 Web 界面中,点击 Manage Jenkins -> Global Tool Configuration。 b. 在 JDK 部分,点击 JDK installations...,然后点击 Add JDK。 c. 输入 JDK 的名称,然后选择 JDK 的安装路径,这里选择之前安装的 JDK 11 的路径:/usr/local/jdk-11.0.1。 d. 点击保存,完成 JDK 的配置。 4. 配置 Jenkins 的 Maven 环境 a. 在 Jenkins 的 Web 界面中,点击 Manage Jenkins -> Global Tool Configuration。 b. 在 Maven 部分,点击 Maven installations...,然后点击 Add Maven。 c. 输入 Maven 的名称,然后选择 Maven 的安装路径,这里选择 /usr/local/apache-maven-3.6.3。 d. 点击保存,完成 Maven 的配置。 至此,CentOS 7 上的 JDK 环境和最新版本的 Jenkins 都已经安装好了,可以在 Jenkins 上进行持续集成和持续部署了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值