简体   繁体   English

向我的虚拟主机添加别名

[英]add alias to my virtual host

I've deployed my project symfony2 on a personal server and everything works fine. 我已经将项目symfony2部署在个人服务器上,并且一切正常。

Now I want to publish this project for some friends so that they can see it. 现在,我想为一些朋友发布此项目,以便他们可以看到它。 I thought that the best would be to access my project from outside through /. 我认为最好的办法是通过/从外部访问我的项目。 Quick google research made think that it's possible with Alias statement. 快速的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>

When I try to access <server_IP_ADDRESS>/<project_name> I got Not found error 当我尝试访问<server_IP_ADDRESS>/<project_name> ,出现Not found错误

Why this error? 为什么会出现这个错误? How do I fix this ? 我该如何解决 ?

UPDATE1 UPDATE1

I have many projects on one server, and I'd like to be able to access them anywhere I'm. 我在一台服务器上有很多项目,我希望能够在任何地方访问它们。 The best option from my point of view is to use Aliases: 从我的角度来看,最好的选择是使用别名:

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

Having a virtual server will map a server to a host name / alias. 拥有虚拟服务器会将服务器映射到主机名/别名。 In your case you are accessing the same host name (the server ip) but different URIs. 在您的情况下,您正在访问相同的主机名(服务器ip),但访问的URI不同。 In your case these URIs may not exist, thus you need to redirect/rewrite them. 在您的情况下,这些URI可能不存在,因此您需要重定向/重写它们。 I think you would be looking for rewrite so you can just go ahead and put rewrite rules in the virtual host definition as in .htaccess just make sure you have mod_rewrite enabled. 我认为您会在寻找重写,因此您可以继续将重写规则放在.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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM