markdown 数字海洋访问和操作

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 数字海洋访问和操作相关的知识,希望对你有一定的参考价值。

# Digital Ocean Access and Operation

## Source article
[The below is a summary of this article](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-16-04)

## Step by step

### Access
`ssh root@SERVER_IP_ADDRESS`

### PM2
PM2 provides an easy way to manage and daemonize applications (run them in the background as a service)

If not already installed, install PM2
`sudo npm install -g pm2`

Use the pm2 start command to run your application in the background:

`pm2 start index.js` where index.js is the start file (in my case likely an express server file)

### Nginx
When you use a URL without a port included your browser assumes it is port 80 (or 443 for HTTPS). Using anything else requires it to be specified. Generally with modern apps using Rails, a JavaScript framework or something other than static HTML or PHP scripts you will use a reverse proxy web server in front of the app to process requests (this also automatically gives you nice standard access logs). What you can do is:

First install nginx

`sudo apt-get update;`
`sudo apt-get install nginx;`
Then once it's installed, edit the nginx configuration file in /etc/nginx/sites-enabled/ so it reads like:

```
server {
        listen   80; 
        server_name example.com; 

     location / {      
        proxy_pass http://localhost:3000;       // where 3000 is your local port
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

     }
}
```
Make sure you didn't introduce any syntax errors by typing:

`sudo nginx -t`

Then restart nginx:

`service nginx restart`

以上是关于markdown 数字海洋访问和操作的主要内容,如果未能解决你的问题,请参考以下文章

markdown Ubuntu部署数字海洋

markdown 数字海洋促销优惠券代码

markdown 01.初始服务器设置数字海洋

markdown 02.初始网络服务器设置数字海洋

markdown 03.初始NGINX服务器设置数字海洋

markdown 在数字海洋上运行Dokku的注意事项。