【发布时间】:2016-09-07 20:09:03
【问题描述】:
我知道这种主题已经问了很多次了,但我没有找到任何符合我需要的答案。首先,我为我的英语道歉。
我想在 VPS 上运行一个节点应用程序和一个(或许多)其他常用网站。 所以你在同一个vps上托管了几个网站,我必须使用apache的virtualhost对吗?这就是我所做的:在 /var/www 我有 2 个目录:test1 和 test2。我想要的是 test1 将是我的节点应用程序,可以通过 test1.my_domain 访问,而 test2 将是一个随机的其他网站,可以通过 test2.my_domain 访问。为此,我已经像这样配置 apache:
/etc/apache2/sites_available/默认:
<VirtualHost *:80>
ServerAdmin contact@my_domain
ServerName my_domain
ServerAlias www.my_domain
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
/etc/apache2/sites_available/test1.conf:
<VirtualHost *:80>
ServerAdmin contact@my_domain
ServerName my_domain
ServerAlias test1.my_domain
DocumentRoot /var/www/test1
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/test1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
/etc/apache2/sites_available/test2.conf:
<VirtualHost *:80>
ServerAdmin contact@my_domain
ServerName my_domain
ServerAlias test2.my_domain
DocumentRoot /var/www/test2
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/test2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
如果 test1 不是节点应用程序,此配置可以完美运行。我的意思是当我去 test1.my_domain 时,我会得到 /var/www/test1 的内容,如果我去 test2.my_domain >,我得到了/var/www/test2的内容。
但是如果我把一个节点应用程序放在 test1 中,节点进入与 apache 冲突,因为它们都使用端口 80。
我看过很多教程通过使用 apache 的代理来解决这个问题,但我不知道如何很好地使用它。 我确切地说我可以让节点监听 80 以外的其他端口,但我不想这样做,因为如果我这样做,url 将是 test1.my_domain:7777 (例如),它是丑对不对?
我也是 vps 配置领域的初学者,所以请尽可能多地描述你的答案;)。
谢谢大家!
【问题讨论】:
标签: node.js apache proxy virtualhost vps