apache2 安装与部署网页
来源:互联网 发布:前程无忧常州数控编程 编辑:程序博客网 时间:2024/06/10 21:33
几个月前研究了下apache2的架构与部署,时隔那么长时间发现居然全忘了,不得不重新来一遍,写一片日志方便以后查阅。
首先我用的是ubuntu系统,不为别的,光是它方便的软件安装与卸载过程就令你无法抗拒。特别是在Redhat下面挣扎数小时,安装成功一个软件,突然发现在Ubuntu下只需要一行命令的时候,你的心中就有了决定。当然,Redhat下也有它自己的yum命令,但是个人觉得还是远没有Ubuntu好用。
1. apache2的安装
言归正转,首先是安装apache2.
简简单单一句话:#apt-get install apache2
一系列刷屏完成之后,apache2的各个组成部分被安装在5个地方:
- 配置文件的位置:/etc/apache2
- lib文件的位置:/usr/lib
- 启动文件的位置:/etc/init.d/apache2
- 网页存放位置:/var/www
- 软件所在位置:/usr/share/apache2
如果对Ubuntu下的软件安装不熟悉,可以参考:http://blog.csdn.net/lrenjundk/article/details/7082620
2. apache2的启动与关闭
启动与关闭apache2可以使用以下命令:- 启动:/etc/init.d/apache2 start 或者 apache2ctl start
- 关闭:/etc/init.d/apache2 stop 或者 apache2ctl stop
- 重启:/etc/init.d/apache2 restart 或者 apache2ctl restart
3. 网页部署:
在apache2下面部署网页也相当简单,首先打开配置文件目录:
#cd /etc/apache2
root@lrenjundk-virtual-machine:/etc/apache2# ls
apache2.conf envvars magic mods-enabled sites-available
conf.d httpd.conf mods-available ports.conf sites-enabled
3.1 apache参数:
在该目录下,最为重要的是apache2.conf文件,其中包含了apache的主要参数,包括可以配置的线程数量,进程数量,用户数量,服务器数量等等:
<IfModule mpm_worker_module> StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxClients 150 MaxRequestsPerChild 0</IfModule><IfModule mpm_event_module> StartServers 2 MinSpareThreads 25 MaxSpareThreads 75 ThreadLimit 64 ThreadsPerChild 25 MaxClients 150 MaxRequestsPerChild 0</IfModule><IfModule mpm_prefork_module> StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxClients 150 MaxRequestsPerChild 0</IfModule>
3.2 链接网页
要链接网页首先需要在/var/www 中创建自己的网页,此处已经有一张默认的网页index.html。也就是apache2启动后默认的那张It works。
建立自己的网站,首先需要创建一个独立的文件夹,以区分不同的网站,并且能确保他们之间互不影响。当然,apache可以同时启动多个虚拟站,那是后话。
#mkdir wsclient
#cp /usr/my.html .
这样我们就能进入网页部署的第二步,打开apache配置文件夹,我们会发现在这下面有两个名为 sites-available和sites-enabled的文件夹。首先打开sites-available,其中保存了我们网站的虚拟机配置信息。对于我们的网页,我们可以新建一个名为wsclient的文件,并进行以下编辑
NameVirtualHost *<VirtualHost *:8080> ServerAdmin webmaster@localhost DocumentRoot /var/www/wsclient <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/wsclient> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory></VirtualHost>
先不要管其他内容,我们需要注意的是如果绑定我们原本的文件夹到此虚拟机上,关键语句:
DocumentRoot /var/www/wsclient
最后,有了虚拟机和网站信息,还需要打开apache下的另一个文件夹sites-enabled,将虚拟机注册到apache上,当apache启动的时候,会自动启动虚拟机。我们的网站也就能站成运行了:
#cd ../sites-enabled
#ln -s ../sites-abailable/wsclient wsclient
大功告成,打开浏览器,输入localhost或者你机器的ip就能显示你所编辑的网页了
- apache2 安装与部署网页
- apache2 安装与配置
- apache2 安装与配置
- apache2 安装与配置
- ArcIMS9.0安装与部署(Apache2.0.52+JDK5.0+Tomcat5.5.4)
- ArcIMS9.0安装与部署(Apache2.0.52+JDK5.0+Tomcat5.5.4)
- ArcIMS9.0安装与部署(Apache2.0.52+JDK5.0+Tomcat5.5.4)
- Linux下安装apache2.2.29、部署静态html
- apache2.2.21(x64)+php(x64),安装+部署 windows版
- linux安装apache2部署html并修改默认访问路径
- tilecache2.11在windows apache2.22安装部署
- apache2(一)程序安装与基本配置
- Apache2 PHP4 Mysql的安装与设置
- Apache2.2.x 安装与配置详解
- PHP7.1.5 安装与 apache2.4链接
- Linux下Apache2的安装与配置
- Apache2 安装
- apache2安装
- SSH的优缺点
- jquery ------ 10个强大的遍历函数
- ServicesDemo - Using Android Services
- 要有自己的核心竞争力,应对时代变迁
- 也谈用友被面试经历【去年杭州用友被拒】
- apache2 安装与部署网页
- OpenCV學習心得(3) -- 在MFC上顯示圖像
- 推荐几本C语言的好书!!!!
- 新浪微博Android SDK——如何打印出5位错误码
- telnet
- Android开发教程之--Activity的生命周期
- 音速启动vstart 目录作用详解
- GridView 合并行或列
- js try catch