xampp中apache使用域名訪問
一、首先找到/opt/lampp/etc/httpd.conf:
- # Virtual hosts
- Include etc/extra/httpd-vhosts.conf
- # Virtual hosts
- Include etc/extra/httpd-vhosts.conf
去掉 Include etc/extra/http-vhosts.conf 前面的#號(以上我已經去掉)
二、修改 /opt/lampp/etc/extra/httpd-vhost.conf
- <VirtualHost *:80>
- ServerAdmin webmaster@dummy-host.example.com
- DocumentRoot /opt/lampp/htdocs/b (這里寫上所綁定到的目錄)
- ServerName www.linuxidc.com (這里寫上域名)
- ServerAlias www.dummy-host.example.com
- ErrorLog logs/dummy-host.example.com-error_log
- CustomLog logs/dummy-host.example.com-access_log common
- </VirtualHost>
- <VirtualHost *:80>
- ServerAdmin webmaster@dummy-host.example.com
- DocumentRoot /opt/lampp/htdocs/b (這里寫上所綁定到的目錄)
- ServerName www.linuxidc.com (這里寫上域名)
- ServerAlias www.dummy-host.example.com
- ErrorLog logs/dummy-host.example.com-error_log
- CustomLog logs/dummy-host.example.com-access_log common
- </VirtualHost>
如我的配置文件如下:
- <VirtualHost *:80>
- DocumentRoot "/opt/lampp/htdocs/"
- ServerName dev.mansys.com
- </VirtualHost>
- <VirtualHost *:80>
- DocumentRoot "/opt/lampp/htdocs/"
- ServerName dev.mansys.com
- </VirtualHost>
三、修改 /etc/hosts ,添加
- 127.0.0.1 dev.mansys.com
- 127.0.0.1 dev.mansys.com
我的如下:
- 127.0.0.1 localhost
- 127.0.0.1 dummy-host.example.com
- 127.0.0.1 dev.example.com
- 127.0.0.1 dev.mansys.com
- 127.0.0.1 localhost
- 127.0.0.1 dummy-host.example.com
- 127.0.0.1 dev.example.com
- 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 ,修改后我的配置文件如下:
- <VirtualHost *:80>
- DocumentRoot "/opt/lampp/htdocs/"
- ServerName dev.mansys.com
- <Directory "/opt/lampp/htdocs/">
- AllowOverride All
- Order deny,allow
- Allow from all
- Require all granted
- </Directory>
- </VirtualHost>
- <VirtualHost *:80>
- DocumentRoot "/opt/lampp/htdocs/"
- ServerName dev.mansys.com
- <Directory "/opt/lampp/htdocs/">
- AllowOverride All
- Order deny,allow
- Allow from all
- Require all granted
- </Directory>
- </VirtualHost>
再次訪問,即可正常訪問