设为首页 收藏本站
查看: 2001|回复: 0

[经验分享] apache 2 修改虚拟目录

[复制链接]

尚未签到

发表于 2015-8-1 08:44:28 | 显示全部楼层 |阅读模式
  准备好环境,就要开始进行开发了。这一篇,我们在Ubuntu Apache上配置虚拟目录。
  
  知识准备:
  区别于Windows 下apache,配置文件通常只有一个,就是httpd.conf。
  Linux下 Apache的配置文件是 /etc/apache2/apache2.conf,Apache在启动时会自动读取这个文件的配置信息。而其他的一些配置文件,如 httpd.conf等,则是通过Include指令包含进来。
  在apache2.conf里有sites-enabled目录,而在 /etc/apache2下还有一个sites-available目录,其实,这里面才是真正的配置文件,而sites- enabled目录存放的只是一些指向这里的文件的符号链接,你可以用ls /etc/apache2/sites-enabled/来证实一下。
  所以,如果apache上配置了多个虚拟主机,每个虚拟主机的配置文件都放在 sites-available下,那么对于虚拟主机的停用、启用就非常方便了:当在sites-enabled下建立一个指向某个虚拟主机配置文件的链 接时,就启用了它;如果要关闭某个虚拟主机的话,只需删除相应的链接即可,根本不用去改配置文件。
  
  了解这些以后,就开始配置apache之旅吧~
  
  1. copy /etc/apache2/sites-avaliable/default , 命名为 chaichunyan
  2.修改配置文件:chaichunyan
  



[html] view plaincopy

  •   
  •         ServerAdmin webmaster@localhost  
  •   
  •         ServerName www.ccy.com  
  •   
  •         DocumentRoot /var/www/ccy  
  •          
  •                 Options Indexes FollowSymLinks MultiViews  
  •                 AllowOverride None  
  •                 Order allow,deny  
  •                 allow from all  
  •          
  •   
  •         ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/  
  •          
  •                 AllowOverride None  
  •                 Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch  
  •                 Order allow,deny  
  •                 Allow from all  
  •          
  •   
  •         ErrorLog ${APACHE_LOG_DIR}/error.log  
  •   
  •         # Possible values include: debug, info, notice, warn, error, crit,  
  •         # alert, emerg.  
  •         LogLevel warn  
  
前提是你已经在 /var/www 下已经cychai目录
  
  3. 建立链接文件:
  
  sudo ln -s /etc/apache2/sites-available/chaichunyan  /etc/apache2/sites-enabled/chaichunyan
  
  4. 重启apache 服务器
  sudo /etc/init.d/apache2 restart
  
  5. 客户端(如windows 7)修改hosts
  添加
  192.168.102.8     www.ccy.com
  Internet 选线--连接 -- 添加例外
  
  6. 访问
  www.ccy.com OK,配置成功!
  
  Reference:
  Ubuntu上安装Apache,每次重启,都会出现以下错误提示:
  Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
  解决方法:
  http://blog.iyunv.com/klinghr/article/details/5378271
  
  ubuntu apache2配置详解(含虚拟主机配置方法)
  http://www.guanwei.org/post/LINUXnotes/01/ubuntuapache2configure.html
  
  
  
Apache2: Virtual Hosts in ubuntu

  Virtual Hosts
Apache2 has the concept of sites, which are separate configuration files that Apache2 will read. These are available in /etc/apache2/sites-available. By default, there is one site available called default this is what you will see when you browse to http://localhost or http://127.0.0.1. You can have many different site configurations available, and activate only those that you need.
  As an example, we want the default site to be /home/user/public_html/. To do this, we must create a new site and then enable it in Apache2.
  To create a new site:
  Copy the default website as a starting point.




sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/mysite
  Edit the new configuration file in a text editor “sudo nano” on the command line or “gksudo gedit”, for example:




gksudo gedit /etc/apache2/sites-available/mysite
  Change the DocumentRoot to point to the new location. For example, /home/user/public_html/
Change the Directory directive, replace to
You can also set separate logs for each site. To do this, change the ErrorLog and CustomLog directives. This is optional, but handy if you have many sites
Save the file
Now, we must deactivate the old site, and activate our new one. Ubuntu provides two small utilities that take care of this: a2ensite (apache2enable site) and a2dissite (apache2disable site).




sudo a2dissite default && sudo a2ensite mysite
  Finally, we restart Apache2:




sudo /etc/init.d/apache2 restart
  If you have not created /home/user/public_html/, you will receive an warning message
  To test the new site, create a file in /home/user/public_html/:




echo 'Hello! It is working!' > /home/user/public_html/index.html
  Finally, browse to http://localhost/
  The above content was taken from the website at https://help.ubuntu.com/community/ApacheMySQLPHP
  http://www.anisjendoubi.com/tag/httpd/

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-92867-1-1.html 上篇帖子: 一周搞定php+apache+mysql 下篇帖子: Redmine+Apache+SVN+SMTP的安装配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表