简体   繁体   English

使用Nginx设置代理

[英]Setting up a proxy with nginx

Not sure if this is actually called a proxy Here is what I have: 不知道这是否实际上称为代理这是我所拥有的:

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

My website is at mckelvey.me:1122 I want my website to be at mckelvey.me. 我的网站是mckelvey.me:1122我希望我的网站是mckelvey.me。 I have no idea how to do this. 我不知道该怎么做。 The ip is 104.131.153.117 and the node application is at /home/deploy than I have a file called deploy.tar that has the website. IP是104.131.153.117,节点应用程序位于/ home / deploy,而不是我有一个名为deploy.tar的文件,该文件具有网站。 It runs perfectly at mckelvey.me:1122 它在mckelvey.me:1122上完美运行

heres the bash script I use to deploy my website: 这是我用来部署网站的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

Here is the Nginx configuration you should have in order to set the reverse proxy up for your Nodejs application: 这是为了为Node.js应用程序设置反向代理而应具有的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;
    }
}

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

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