简体   繁体   English

使用Nginx的Node.js服务器上的反向代理?

[英]Reverse proxy on a Node.js server using Nginx?

Okay, I'm about at my wits end here. 好吧,我快要结束了。 I have an Express server running an Angular app. 我有一个运行Angular应用程序的Express服务器。 Using this guy's tutorial http://antrikshy.com/blog/deploy-an-expressjs-app-on-digital-ocean-complete-succinct-guide/ 使用此人的教程http://antrikshy.com/blog/deploy-an-expressjs-app-on-digital-ocean-complete-succinct-guide/

I have my app running at my Digital Ocean IP address + port 8000. I've created an upstart service so it's always running. 我的应用程序在Digital Ocean IP地址+端口8000上运行。我创建了新贵服务,因此该服务始终处于运行状态。 I also installed Nginx and its Welcome screen is up at my DO IP address. 我还安装了Nginx,其欢迎屏幕位于我的DO IP地址上。 So now I need to configure nginx so I can access my site with just the IP address. 因此,现在我需要配置nginx,以便仅使用IP地址即可访问我的站点。

I tried doing what the guy in the tutorial did, but mine just isn't working... What am I doing wrong? 我试着做教程中那个家伙所做的事情,但是我的行不通...我在做什么错?

Here's my set up: 这是我的设置:
Using WinSCP I uploaded my app into "/home/stuffie" on my server, then I uploaded a .conf file called "KamiAng.conf" into the "/etc/init" folder as you can see in the image below. 使用WinSCP,我将应用程序上传到服务器上的“ / home / stuffie”中,然后将名为“ KamiAng.conf”的.conf文件上传到了“ / etc / init”文件夹中,如下图所示。

应用文件夹快照 **Note: The app.js file is the file that starts my node server. **注意:app.js文件是启动我的节点服务器的文件。

Here's the contents of KamiAng.conf 这是KamiAng.conf的内容

# Goes in /etc/init/

description "Keep my site up"

start on startup
start on filesystem and started networking
stop on shutdown
respawn

chdir /home/stuffie/KamiAng
env NODE_ENV=production
env PORT=8000
exec node app.js

And this works! 这有效! When I type in "sudo start KamiAng" my site stays up at IP:8000 even when I close out of the terminal. 当我输入“ sudo start KamiAng”时,即使关闭终端,我的站点仍处于IP:8000。 Like I mentioned above I installed nginx and it's running at my IP address. 就像我上面提到的那样,我安装了nginx并在我的IP地址上运行。

So now I'm trying to configure ports with nginx. 所以现在我正在尝试使用nginx配置端口。

In the "/etc/nginx/conf.d/" folder I've added a file called "kamicon.conf" Here's that file: 在“ /etc/nginx/conf.d/”文件夹中,我添加了一个名为“ kamicon.conf”的文件。以下是该文件:

# Goes in /etc/nginx/conf.d/

upstream kamicon {
    server **myIP**:8000;
}

server {
    listen 0.0.0.0:80;
    server_name stuffiestephie.com www.stuffiestephie.com;

    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 Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header X-NginX-Proxy true;
      proxy_pass http://kamicon/;
      proxy_redirect off;
    }
 }

According to the tutorial I linked to, at this point I should be able to enter "sudo service nginx reload" and run my app again using "npm start". 根据我链接的教程,这时我应该能够输入“ sudo service nginx reload”并使用“ npm start”再次运行我的应用程序。 This however, does not work. 但是,这不起作用。

错误

After starting entering "sudo service nginx reload", I enter "npm start" which results in an error because my package.json isn't in "/home/stuffie/" so then I change directories to "KamiAng" (where the package.json file is) and enter "npm start" and I get the errors seen in the above image. 在开始输入“ sudo service nginx reload”之后,我输入“ npm start”,这会导致错误,因为我的package.json不在“ / home / stuffie /”中,因此我将目录更改为“ KamiAng”(其中.json文件是),然后输入“ npm start”,我得到上图所示的错误。

I'm losing it here... What am I doing wrong? 我在这里丢了...我在做什么错? I just really need this server up. 我只是真的需要这个服务器。

Any help is really appreciated! 任何帮助都非常感谢!

尝试在chdir /home/stuffie/KamiAngchdir /home/stuffie/KamiAng/

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

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