2016-09-07 9 views
1

私はこの種の主題が何度も尋ねられてきたことは知っていますが、私の必要性に合った答えは見つかりませんでした。まず、私は英語を謝っています。Apacheの横にあるNodeJS

VPSでノードアプリケーションとその他の通常のWebサイトを実行したいとします。 同じvpsでいくつかのWebサイトをホストしているので、私はApacheから仮​​想ホストを正しく使用する必要がありますか?だからそれは私がやったことです:/var/www私は2つのディレクトリ:test1test2を持っています。私が望むのは、test1が私のノードアプリケーションで、test1.my_domainでアクセス可能で、test2がtest2.my_domainでアクセス可能なランダムな他のWebサイトになることです。そのためには、私はこのようなApacheの設定をしました:

は/ etc/apache2の/ sites_available /デフォルト:

<VirtualHost *:80> 
ServerAdmin [email protected]_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 [email protected]_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 [email protected]_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がノードappliでない場合は正常に動作しますカチオン。私は私がtest1.my_domainに行くとき、私はの/ var/www /のtest1ののコンテンツを取得することを意味し、私はtest2.my_domainに行けば、私はの/ var/www /のTEST2のコンテンツを取得。

しかし、私はtest1の内のノードのアプリケーションを置く場合、それらの両方が、私は、Apacheののproxysを使用することによってこれを解決するために、多くのチュートリアルを見てきましたが、私は理解することはできませんポート80

を使用しているため、ノードは、Apacheと競合して入力してくださいそれをうまく使用する方法を説明します。 私はノードが80よりも他のポートを聞くことができますが、私はURLをtest1.my_domain:7777(たとえば)とすると、それは醜いのですから、そうするのは嫌いではありませんか?

また、私はvps設定のドメインの初心者ですので、可能な限り答えを記述してください。

ありがとうございました!ポート7777上の

答えて

0

実行ノードアプリ、とはtest1.confとしてこれを使用します。これにより

<VirtualHost *:80> 
ServerAdmin [email protected]_domain 
ServerName test1.my_domain 

ProxyPreserveHost On 
ProxyPass/http://127.0.0.1:7777/ 
ProxyPassReverse/http://127.0.0.1:7777/ 

</VirtualHost> 

は、あなたのノードアプリが助けをhttp://test1.my_domain

+0

[OK]をおかげで到達可能でなければならない、私はそれを後でしようとします。しかし、この設定では、http://test1.my_domainが/ var/www/test1にあることをサーバがどのように知っていますか? – toto1911

+0

apacheはノード_files_がどこにあるか(またはノードapp、tomcatサーバーなど)気にしませんが、test1.my_domainのリクエストをポート7777 –

+0

btwで実行されているアプリに転送します。 **一般的なセットアップ、あなたはこの要件の最初ではありません:) –

関連する問題