linux下xampp(apache)中配置域名访问,以及遇到的问题

xampp中apache使用域名访问

一、首先找到/opt/lampp/etc/httpd.conf:

 

[plain]  view plain  copy
 
  1. # Virtual hosts  
  2. Include etc/extra/httpd-vhosts.conf  
[plain]  view plain  copy
 
  1. # Virtual hosts  
  2. Include etc/extra/httpd-vhosts.conf  

去掉 Include etc/extra/http-vhosts.conf 前面的#号(以上我已经去掉)

 

二、修改 /opt/lampp/etc/extra/httpd-vhost.conf

 

[html]  view plain  copy
 
  1. <VirtualHost *:80>  
  2.     ServerAdmin webmaster@dummy-host.example.com  
  3.     DocumentRoot /opt/lampp/htdocs/b    (这里写上所绑定到的目录)  
  4.     ServerName www.linuxidc.com                              (这里写上域名)  
  5.     ServerAlias www.dummy-host.example.com  
  6.     ErrorLog logs/dummy-host.example.com-error_log  
  7.     CustomLog logs/dummy-host.example.com-access_log common  
  8.  </VirtualHost>  
[html]  view plain  copy
 
  1. <VirtualHost *:80>  
  2.     ServerAdmin webmaster@dummy-host.example.com  
  3.     DocumentRoot /opt/lampp/htdocs/b    (这里写上所绑定到的目录)  
  4.     ServerName www.linuxidc.com                              (这里写上域名)  
  5.     ServerAlias www.dummy-host.example.com  
  6.     ErrorLog logs/dummy-host.example.com-error_log  
  7.     CustomLog logs/dummy-host.example.com-access_log common  
  8.  </VirtualHost>  

 

如我的配置文件如下:

 

[html]  view plain  copy
 
  1. <VirtualHost *:80>  
  2.     DocumentRoot "/opt/lampp/htdocs/"  
  3.     ServerName dev.mansys.com  
  4. </VirtualHost>  
[html]  view plain  copy
 
  1. <VirtualHost *:80>  
  2.     DocumentRoot "/opt/lampp/htdocs/"  
  3.     ServerName dev.mansys.com  
  4. </VirtualHost>  


三、修改 /etc/hosts ,添加

 

 

[html]  view plain  copy
 
  1. 127.0.0.1      dev.mansys.com  
[html]  view plain  copy
 
  1. 127.0.0.1      dev.mansys.com  

我的如下:

 

 

[html]  view plain  copy
 
  1. 127.0.0.1       localhost  
  2.   
  3. 127.0.0.1       dummy-host.example.com  
  4. 127.0.0.1       dev.example.com  
  5. 127.0.0.1       dev.mansys.com  
[html]  view plain  copy
 
  1. 127.0.0.1       localhost  
  2.   
  3. 127.0.0.1       dummy-host.example.com  
  4. 127.0.0.1       dev.example.com  
  5. 127.0.0.1       dev.mansys.com  

 

 

然后访问: dev.mansys.com 即可

如果出现以下错误:

Object not found!


The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.


If you think this is a server error, please contact the webmaster.
Error 404
dummy-host.example.com
Apache/2.4.23 (Unix) OpenSSL/1.0.2h PHP/5.5.38 mod_perl/2.0.8-dev Perl/v5.16.3 

修改修改 /opt/lampp/etc/extra/httpd-vhost.conf ,修改后我的配置文件如下:

 

[html]  view plain  copy
 
  1. <VirtualHost *:80>  
  2.     DocumentRoot "/opt/lampp/htdocs/"  
  3.     ServerName dev.mansys.com  
  4.     <Directory "/opt/lampp/htdocs/">  
  5.         AllowOverride All  
  6.         Order deny,allow  
  7.         Allow from all  
  8.         Require all granted  
  9.     </Directory>  
  10. </VirtualHost>  
[html]  view plain  copy
 
  1. <VirtualHost *:80>  
  2.     DocumentRoot "/opt/lampp/htdocs/"  
  3.     ServerName dev.mansys.com  
  4.     <Directory "/opt/lampp/htdocs/">  
  5.         AllowOverride All  
  6.         Order deny,allow  
  7.         Allow from all  
  8.         Require all granted  
  9.     </Directory>  
  10. </VirtualHost>  

 

 

再次访问,即可正常访问

转载于:https://www.cnblogs.com/SofuBlue/p/8027102.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值