我目前在LAMP服务器上设置了一个域,我想添加另一个域。我尝试自己做,但当遇到问题时,我会关注this。
我设置了example.com并且工作正常,所有流量都会重定向到其https,我想继续这样做。我现在在尝试重新启动apache2后收到错误消息:
script '/var/www/html/test.ca/public_html/httptest.php' not found or unable to stat
我在我的apache2.conf文件中搜索httptest.php
,但没有匹配。
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName test.ca
Redirect permanent / http://test.ca
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/ssl/localcerts/example.com.crt
SSLCertificateKeyFile /etc/ssl/localcerts/example.com.key
SSLCACertificateFile /etc/ssl/localcerts/intermediate.crt
ServerAdmin example@gmail.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com/public_html/
ErrorLog /var/www/html/example.com/logs/error.log
CustomLog /var/www/html/example.com/logs/access.log combined
<Directory /var/www/html/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerAdmin example@gmail.com
ServerName test.ca
ServerAlias www.test.ca
DocumentRoot /var/www/html/test.ca/public_html/
ErrorLog /var/www/html/test.ca/logs/error.log
CustomLog /var/www/html/test.ca/logs/access.log combined
<Directory /var/www/html/test.ca/>
Require all granted
</Directory>
</VirtualHost>
/etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/ssl/localcerts/example.com.crt
SSLCertificateKeyFile /etc/ssl/localcerts/example.com.key
SSLCACertificateFile /etc/ssl/localcerts/intermediate.crt
ServerAdmin example@gmail.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com/public_html/
ErrorLog /var/www/html/example.com/logs/error.log
CustomLog /var/www/html/example.com/logs/access.log combined
<Directory /var/www/html/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
/etc/apache2/sites-available/test.ca.conf
<VirtualHost *:80>
ServerName test.ca
Redirect permanent / http://test.ca
</VirtualHost>
<VirtualHost *:444>
ServerAdmin example@gmail.com
ServerName test.ca
ServerAlias www.test.ca
DocumentRoot /var/www/html/test.ca/public_html/
ErrorLog /var/www/html/test.ca/logs/error.log
CustomLog /var/www/html/test.ca/logs/access.log combined
<Directory /var/www/html/test.ca/>
Require all granted
</Directory>
</VirtualHost>
我的/ etc / hosts文件说(它有我的ip):
127.0.0.1 myservername
当我在/ var / www / html中执行ls -l
时,我得到:
-rw-r--r-- 1 root root 11510 Dec 15 20:49 index.html
drwxr-xr-x 4 root root 4096 Jan 11 19:19 test.ca
drwxr-xr-x 4 root root 4096 Dec 15 21:00 example.com
然后将其更改为:
-rw-r--r-- 1 root root 11510 Dec 15 20:49 index.html
drwxr-xr-x 4 sys sys 4096 Jan 11 19:19 test.ca
drwxr-xr-x 4 sys sys 4096 Dec 15 21:00 example.com
我已经运行了下面的代码,它说两者都启用了:
sudo a2ensite example.com
sudo a2ensite test.ca
apache重启时发生错误。
答案 0 :(得分:1)
您是否已激活虚拟主机?如果不是......
使用内置的apache快捷方式激活主机:
sudo a2ensite example.com
sudo a2ensite test.ca
重启Apache服务:
sudo service apache2 restart
还要检查项目文件夹的权限