有您需要按照設置的虛擬主機上的Ubuntu幾個步驟: 讓我們說你的項目文件夾的名字是myProject的
步驟1:將的/ var裏面的文件夾/ www/html等
sudo mv ~/myProject /var/www/html/
步驟2:給項目文件夾的所有權到WWW的數據
sudo chown -R www-data:www-data /var/www/html/myProject
步驟3:C reate新網站內提供的網站:
cd /etc/apache2/sites-available/
ls
在這裏你會看到現有的000-default.conf和默認的ssl.conf .Copy兩個文件的內容到一個文件中並替換您的文件夾名稱或拷貝一個到名爲myProject的新文件中。CONF
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/myProject/
ServerName project.com
ServerAlias www.project.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin [email protected]
DocumentRoot /var/www/html/myProject/
ServerName project.com
ServerAlias www.project.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/mobidev_cert.pem
SSLCertificateKeyFile /etc/ssl/certs/mobidev_key.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
包括在此自簽名證書也路徑如圖所示的SSL密鑰,並且可以很容易地下載的SSL證書。
第4步:將您的項目添加到Apache配置文件。
sudo vi /etc/apache2/apache2.conf
把這個文件中的行:
DocumentRoot "/var/www/html/myProject"
<Directory /var/www/html/myProject/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
第5步:添加您的虛擬服務器名稱(在myProject.conf指定)到主機file.add該行:
sudo gedit /etc/hosts
127.0.1.1 project.com
第6步:現在所有設置,啓用網站,重新啓動apache
sudo a2ensite /etc/apache2/sites-availabl/myProject.conf
sudo systemctl reload apache2
sudo update-rc.d apache2 defaults
sudo update-rc.d mysql defaults
sudo a2enmod ssl
sudo a2ensite default-ssl
只需在瀏覽器中點擊project.com即可。
感謝您的建議,我找到了解決方案。我在定義虛擬主機塊上面放置了一些默認目錄: DocumentRoot/xampp/htdocs VirtualHost>這將呈現與定義的虛擬主機不匹配的所有請求。 –
Trez
2010-11-03 04:59:15