linux下配置apache虛擬主機解決方案以及一些問題
回南昌了,發現這邊很多公司都是用apache的,上海那邊都是使用nginx伺服器,可見差距啊
博主今天興致來了,正好之前在Mac虛擬機器上配了一臺apache伺服器,於是就到自己Mac虛擬機器上配置虛擬主機吧(老早的時候我是在win上配置的虛擬主機)
1,首先我配置時候,就沒有找到 httpd-vhosts.conf 這個檔案(在win中配置,好像就直接在conf/extra/裡面了吧);而這裡顯示的位置是:
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
2,於是我就在apache配置httpd.conf中配置 include /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf 但是呢?結果報錯了;
3,然後我就按照httpd.conf中其他include的形式去包涵虛擬主機配置檔案;
這樣copy一份吧(extra是自己建的一個資料夾) cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf/extra
4,然後編輯httpd.conf : 在最下面添加了 Include conf/extra/httpd-vhosts.conf (這種相對路徑是模仿httpd.conf其他包含檔案方式的哦)
注意網上有人將IncludeOptional conf.d/*.conf 給註釋了,這裡是不需要注視的!!!
5,配置下httpd-vhosts.conf檔案:
<VirtualHost *:80>
ServerName www.blog.com
DocumentRoot "/var/www/project/blog"
<Directory "/var/www/project/blog/public">
AllowOverride All
Require all granted
Options all #開啟目錄瀏覽
</Directory>
ErrorLog "/var/log/httpd/dummy-host2.example.com-error_log"
CustomLog "/var/log/httpd/dummy-host2.example.com-access_log" common
</VirtualHost>
6,然後重啟service httpd restart
7,繫結下hosts就可以訪問了