使用nginx设置代理

时间:2015-05-09 18:59:38

标签: node.js nginx server

不确定这实际上是否称为代理 这就是我所拥有的:

server {
        listen 80;
        listen mckelvey.me:1122
        server_name mckelvey.me
        location / {
                /personal-website
        }
}

我的网站是在mckelvey.me:1122 我希望我的网站在mckelvey.me。 我不知道该怎么做。 ip是104.131.153.117,节点应用程序在/ home / deploy,而不是我有一个名为deploy.tar的文件,它有网站。它在mckelvey.me:1122

完美运行

继承人我用来部署我的网站的bash脚本:

#! /usr/bin/env bash
set -e

remote_deploy_dir=/srv/personal_website

remote_host=mckelvey.me
remote_user=deploy
remote_port=22

echo
echo Compressing codebase for push
tar c -f deploy.tar --exclude deploy.tar .

echo
echo Uploading codebase
scp -P $remote_port deploy.tar $remote_user@$remote_host:.
rm deploy.tar

ssh -T -p $remote_port $remote_user@$remote_host <<END_SSH_COMMANDS
  set -o xtrace
  echo
  echo Creating $remote_deploy_dir
  sudo mkdir -p $remote_deploy_dir
  cd $remote_deploy_dir

  echo
  echo Stopping old site instace
  forever stop index.js || echo no old instance found

  echo
  echo Extracting codebase
  sudo tar xf ~/deploy.tar -C .

  echo
  echo Starting new site instance
  forever start index.js
END_SSH_COMMANDS

1 个答案:

答案 0 :(得分:3)

以下是为Nodejs应用程序设置反向代理所需的Nginx配置:

server {
    listen 80;
    server_name mckelvey.me;
    location / {
        proxy_pass http://104.131.153.117:1122;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}