linux下Apache2简单配置

**

Apache2配置

环境要求:

系统:GNU/Linux Debian/etch
Apache当前版本: 2.0.55-4

安装:

$sudo aptitude update
$sudo aptitude install apache2 apache2-utils //其中apache2-utils提供了我们在配置维护过程中非常有用的一些工具

安装完成后,可以使用下面的命令启动Apache 服务:

 $sudo /etc/init.d/apache2 start

测试:浏览器输入ip 会显示安装成功页面。

2.配置apache2:

主配置目录

$vim /etc/apache2/apache2.conf  //这只是一个主目录,它包含了其他子配置文件,如果你需要的话。

在apache2.conf 中修改为如下代码

如:


#设置端口--------------apache2的2.X版本对配置做了模块化,这里我把它整合了,这样修改起来方便--------
Listen 80
 
#设置主页-----------------------------------------------------
DirectoryIndex  /hello			//优先权从左到右,可以是index.html 其中hello为C的可执行文件  index.php 也可以设置为可执行文件
 
#设置根目录----------------------------------------------
        ServerAdmin webmaster@localhost                  //设置服务邮箱
        DocumentRoot /usr/local/bin			//设置根目录
        ErrorLog ${APACHE_LOG_DIR}/error.log			//设置错误日志
        CustomLog ${APACHE_LOG_DIR}/access.log combined //设置请求日志
 
#设置目录权限------------------------------------
 
<Directory /usr/local/bin/>					//设置其他目录的可访问目录权限
        Options Indexes FollowSymLinks					//如果该虚拟目录下没有 index.html,浏览器也会显示该虚拟目录的目录结构,列出该虚拟目录下的文件和子目录。
        AllowOverride None								//不允许覆盖,即Apache不允许另一配置文件覆盖现有配置文件。
        Require all granted								//请求权限设置为允许所有
</Directory>
 
#--根据需要自己配置cgi-----------------------
 
ScriptAlias /cgi-bin/ /usr/local/bin/		//设置CGI调用路径
<Directory "/usr/local/bin/">				//设置这个目录的权限
         AllowOverride None
         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch	//允许这个目录下运行CGI程序
          Require all granted
</Directory>
 
ScriptAlias /hello /usr/local/cogs/bin      	
 
Alias /cogs-reports /usr/local/adnxs/cogs/reports		//类似软链接,设置目录的缩写形式
 
<Directory /usr/local/adnxs/cogs/reports>				
    Allow from all
    Require all granted
</Directory>
 
#cgi 在mods-enabled中
#---------------其他默认设置----------------
DefaultRuntimeDir ${APACHE_RUN_DIR}
PidFile ${APACHE_PID_FILE}
Timeout 300
KeepAliveTimeout 5
KeepAlive On
MaxKeepAliveRequests 100
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}
HostnameLookups Off
 
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
 
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
 
<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>
 
<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>
 
AccessFileName .htaccess
<FilesMatch "^\.ht">
        Require all denied
</FilesMatch>
 
 
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
 
 
IncludeOptional conf-enabled/*.conf
 
IncludeOptional sites-enabled/*.conf

下面的内容是实现CGI配置配置生效

$apache2ctl -M   //查看已加载模块

cgi_module (shared) 这个默认是没有加载的

$cd /etc/apache2/mods-available   //指定目录查看文件  cgid.load  
$cd /etc/apache2/mods-enabled     //创建软连接到这个目录使模块被调用(类似开关效果,链接起来模块就起作用)
$ln -s /etc/apache2/mods-available/cgid.load  /etc/apache2/mods-enabled/cgid.load

再次执行 a2enmod cgid ,再查看已加载模块是否存在
结合配置文件中的目录设置,Apache2的CGI配置完成

$ service apache2 restart   //重启apache2

到这里我们就可以在本地通过IP访问我们配置文件设置的目录中的主页了。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值