为我的虚拟主机添加别名

add alias to my virtual host

我已经在个人服务器上部署了我的项目 symfony2,一切正常。

现在我想把这个项目发布给一些朋友,让他们看到。我认为最好的办法是通过/从外部访问我的项目。 快速 google 研究认为使用 Alias 语句是可能的。

ServerName blabla
ServerAlias blablab
ServerAdmin blablab@blabla
DocumentRoot /path/to/my/project/web     

Alias /myproject "/path/to/my/project/web"
<Directory /path/to/my/project/web>
   DirectoryIndex app.php
   Options Indexes FollowSymLinks MultiViews
   AllowOverride All
   Require all granted
   Order allow,deny
   allow from all
</Directory>

当我尝试访问 <server_IP_ADDRESS>/<project_name> 时出现 Not found 错误

为什么会出现这个错误?我该如何解决这个问题?

更新1

我在一台服务器上有很多项目,我希望能够随时随地访问它们。从我的角度来看,最好的选择是使用别名:

  1. 项目 1:http://<my_server_ip_address>/project1
  2. 项目 2:http://<my_server_ip_address>/project2
  3. 项目 3:http://<my_server_ip_address>/project3 ....

拥有虚拟服务器会将服务器映射到主机名/别名。在您的情况下,您正在访问相同的主机名(服务器 ip)但不同的 URI。在您的情况下,这些 URI 可能不存在,因此您需要 redirect/rewrite 它们。我想你会寻找重写,这样你就可以继续将重写规则放在虚拟主机定义中,就像 .htaccess 一样,只需确保你启用了 mod_rewrite。

ServerName <server ip>

RewriteEngine On

RewriteRule /project1 /Path/to/project/1 [L]
RewriteRule /project2 /Path/to/project/2 [L]
RewriteRule /project3 /Path/to/project/3 [L]