linux下Apache2简单配置

您所在的位置:网站首页 apache2配置网页 linux下Apache2简单配置

linux下Apache2简单配置

2024-07-07 05:01| 来源: 网络整理| 查看: 265

**

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 //设置请求日志 #设置目录权限------------------------------------ //设置其他目录的可访问目录权限 Options Indexes FollowSymLinks //如果该虚拟目录下没有 index.html,浏览器也会显示该虚拟目录的目录结构,列出该虚拟目录下的文件和子目录。 AllowOverride None //不允许覆盖,即Apache不允许另一配置文件覆盖现有配置文件。 Require all granted //请求权限设置为允许所有 #--根据需要自己配置cgi----------------------- ScriptAlias /cgi-bin/ /usr/local/bin/ //设置CGI调用路径 //设置这个目录的权限 AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch //允许这个目录下运行CGI程序 Require all granted ScriptAlias /hello /usr/local/cogs/bin Alias /cogs-reports /usr/local/adnxs/cogs/reports //类似软链接,设置目录的缩写形式 Allow from all Require all granted #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 Options FollowSymLinks AllowOverride None Require all denied AllowOverride None Require all granted AccessFileName .htaccess Require all denied 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访问我们配置文件设置的目录中的主页了。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3