虚拟主机和别名的问题 Laravel 5.4
Problems with virtualhost and alias Laravel 5.4
我正在尝试使用带有别名的虚拟主机来部署 Laravel 应用程序。
在 ubuntu 16.04.
中使用 apache2
我的 000.conf 文件是:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/public
Alias /expediente "/var/www/public/"
<Directory /var/www/public/>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
第一个工作正常,但第二个不工作。
我做错了什么?
==============
编辑
好的,所以我在站点中创建了两个可用的 conf 文件,并将它们符号链接到启用站点。
advanced.conf
<VirtualHost *:80>
ServerAdmin admin@localhost
ServerName ip-address:80/advanced
ServerAlias /advanced
DocumentRoot /var/www/html/advanced
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
expediente.conf
<VirtualHost *:80>
ServerAdmin admin@localhost
ServerName ip-address:80/expediente
ServerAlias /expediente
DocumentRoot /var/www/html/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
重新加载并重新启动 apache2。
如果我尝试导航到 ip-address/,我会看到第一页,即高级页面,
如果我尝试导航到 ip-address/advanced 404 not found
如果我尝试导航到 ip-address/expediente 404 not found
我做错了什么?
您的虚拟主机配置中需要 ServerName,如果没有它,它可能总是默认为第一个。例如
服务器名称mydomain.net
如果你的项目是http://localhost/AppName的形式,那么你必须把它放在httpd.conf
<VirtualHost site1.local:80>
ServerAdmin webmaster@example.com
DocumentRoot /path/to/htdocs/site1
ServerName www.site1.local
ServerAlias site1.com
</VirtualHost>
第二个
<VirtualHost site2.local:80>
ServerAdmin webmaster@example.com
DocumentRoot /path/to/htdocs/site2
ServerName www.site2.local
ServerAlias site2.com
</VirtualHost>
最好的做法是为您的别名创建不同的主机文件。您可以使用此命令通过此命令复制第二个别名的默认配置
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
然后在你喜欢的任何编辑器中打开它并输入这些内容
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
保存并关闭文件然后运行这个命令
sudo a2ensite example.com.conf
并重启你的apache
我正在尝试使用带有别名的虚拟主机来部署 Laravel 应用程序。 在 ubuntu 16.04.
中使用 apache2我的 000.conf 文件是:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/public
Alias /expediente "/var/www/public/"
<Directory /var/www/public/>
Options -Indexes
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
</IfModule>
</VirtualHost>
第一个工作正常,但第二个不工作。
我做错了什么?
==============
编辑
好的,所以我在站点中创建了两个可用的 conf 文件,并将它们符号链接到启用站点。
advanced.conf
<VirtualHost *:80>
ServerAdmin admin@localhost
ServerName ip-address:80/advanced
ServerAlias /advanced
DocumentRoot /var/www/html/advanced
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
expediente.conf
<VirtualHost *:80>
ServerAdmin admin@localhost
ServerName ip-address:80/expediente
ServerAlias /expediente
DocumentRoot /var/www/html/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
重新加载并重新启动 apache2。
如果我尝试导航到 ip-address/,我会看到第一页,即高级页面, 如果我尝试导航到 ip-address/advanced 404 not found 如果我尝试导航到 ip-address/expediente 404 not found
我做错了什么?
您的虚拟主机配置中需要 ServerName,如果没有它,它可能总是默认为第一个。例如
服务器名称mydomain.net
如果你的项目是http://localhost/AppName的形式,那么你必须把它放在httpd.conf
<VirtualHost site1.local:80>
ServerAdmin webmaster@example.com
DocumentRoot /path/to/htdocs/site1
ServerName www.site1.local
ServerAlias site1.com
</VirtualHost>
第二个
<VirtualHost site2.local:80>
ServerAdmin webmaster@example.com
DocumentRoot /path/to/htdocs/site2
ServerName www.site2.local
ServerAlias site2.com
</VirtualHost>
最好的做法是为您的别名创建不同的主机文件。您可以使用此命令通过此命令复制第二个别名的默认配置
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf
然后在你喜欢的任何编辑器中打开它并输入这些内容
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
保存并关闭文件然后运行这个命令
sudo a2ensite example.com.conf
并重启你的apache