今回はこれまで以上に読みました。これは私の最初のWebページになるので、nodejsにマウントすることにしました。私は非常に迅速にアプリを作成し、localhost:9000 でテストします
VPS上で動作するアプリを増やしたいので、情報を検索し、2つのオプションがあります
最初にnginxを使用してアプリをプロキシします...
upstream example1.com {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name www.example1.com;
rewrite ^/(.*) http://example1.com/$1 permanent;
}
# the nginx server instance
server {
listen 80;
server_name example1.com;
access_log /var/log/nginx/example1.com/access.log;
# pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://example1.com;
proxy_redirect off;
}
}
nginxを使用したことがないため、この構成ファイルを理解できないので、2番目のオプションを検索します
Expressjs() から vhost を使用する
express()
.use(express.vhost('m.mysite.com', require('/path/to/m').app))
.use(express.vhost('sync.mysite.com', require('/path/to/sync').app))
.listen(80)
私はexpressjsを使用していて、構成方法を理解していますが、express()を使用すると複数のアプリを管理する1つのアプリがあるため、最適なオプションについていくつか質問があります。これは良い習慣ではなく、リソースの無駄だと思います。
この投稿から、デビッド・エリスは言います
WebSockets (または実際には HTTP 1.1 機能) を使用する必要がない場合は、代わりに NginX をプロキシとして使用できます。
利点は、NginX が処理できる総負荷とノードが高いことです (基本的に、静的にコンパイルされ、この種のものに特化されています)。ただし、データをストリーミングする機能は失われます (一度に小さなチャンクを送信する)。
小規模なサイトの場合、または将来必要になる機能がわからない場合は、node-http-proxy に固執し、プロキシがサーバーのボトルネックであることを証明できる場合にのみ NginX に切り替えることをお勧めします。幸いなことに、後で必要になった場合でも、NginX をセットアップするのは難しくありません。
この投稿から、多くのアプリでxginxを構成する例を読みましたが、それを使用する方法がわかりません
upstream example1.com {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name www.example1.com;
rewrite ^/(.*) http://example1.com/$1 permanent;
}
# the nginx server instance
server {
listen 80;
server_name example1.com;
access_log /var/log/nginx/example1.com/access.log;
# pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://example1.com;
proxy_redirect off;
}
}
upstream example2.com {
server 127.0.0.1:1111;
}
server {
listen 80;
server_name www.example2.com;
rewrite ^/(.*) http://example2.com/$1 permanent;
}
# the nginx server instance
server {
listen 80;
server_name example2.com;
access_log /var/log/nginx/example2.com/access.log;
# pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://example2.com;
proxy_redirect off;
}
}
問題は、nginx を使用するか、vhost を使用するか、どちらが最良のオプションであるかということです。
nginxを使用する必要がある場合、ノードjsで多くのアプリを提供するようにnginxを構成する方法についてのチュートリアルがあります???
tnx すべて