linux cloud server nginx background build express forwarding

Buy cloud server or a virtual machine set up their own local (and so I use the Tencent server (CVM), or you can purchase ecs Ali cloud server)

购买完成后  配置安全组 允许http  https  ftp  端口    
一般运营商会提供说明,这一步主要是供我们链接服务器和访问服务器所用

配置完安全组之后,浏览器打开公网ip(买了服务器之后就会分配给你)   

这时候会报错  应为服务器没有运行服务程序  所以找不到任何东西

这个时候打开我们的链接工具   putty   输入我们的链接信息  一般账号是root  密码自己重置

登录完成后,下一步 下载我们需要的包

Download various packages (generally used in the background locale service provider provides a corresponding method of installation environment)

1. Install node

    wget https://nodejs.org/dist/v10.16.3/node-v10.16.3-linux-x64.tar.xz
    
    这里的node链接不是最新的,可以去官网换成最新的,一定要linux版本的
    或者直接现在本地机器下载完成后网服务器上丢,不一定非要在服务器来下载

2. Set the connection linux, similar to the window of global variables can be used at any node and npm and a file

    ln -s /root/node-v10.16.3-linux-x64/bin/node /usr/local/bin/node

    ln -s /root/node-v10.16.3-linux-x64/bin/npm  /usr/local/bin/npm

    设置完成后,任意一个文件夹 
    node -v  npm -v
    查看 Node.js 及 npm 版本信息
    当然你还可以设置npm淘宝镜像
    也可以全局安装yarn,同样需要设置yarn的软连接

3. Download nvm, version control node

1) Execute the following command to install git.
    yum install -y git
2) Execute the following command, NVM download the source code and check for the latest version.
    git clone https://github.com/cnpm/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`
3) Execute the following commands to configure NVM environment variables.
    echo ". ~/.nvm/nvm.sh" >> /etc/profile
4) Execute the following command to read the environment variables.
    source /etc/profile
5) Execute the following command to see all Node.js version.
    nvm list-remote
    nvm install v**.**.**
    nvm use v**.**.**

### 4. Install the Nginx
CAT / etc / RedHat-Release

    所有用户 执行这句

    添加 yum 源
    Nginx 不在默认的 yum 源中,可以使用 epel 或者官网的 yum 源,这里使用官网的 yum 源。
    sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

    安装完 yum 源之后,可以查看一下。
    sudo yum repolist
    nginx repo 已经安装了。


    yum 安装 Nginx,一条命令。
    sudo yum install nginx

    设置开机启动
    $ sudo systemctl enable nginx

    启动服务
    $ sudo systemctl start nginx

    停止服务
    $ sudo systemctl restart nginx

    重新加载,因为一般重新配置之后,不希望重启服务,这时可以使用重新加载。
    $ sudo systemctl reload nginx

Also if you want to download unzip installed, you will need to do this
安装所需环境
Nginx 是 C语言 开发,建议在 Linux 上运行

一. gcc 安装
安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境,如果没有 gcc 环境,则需要安装:

yum install gcc-c++


二. PCRE pcre-devel 安装
PCRE(Perl Compatible Regular Expressions) 是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式,所以需要在 linux 上安装 pcre 库,pcre-devel 是使用 pcre 开发的一个二次开发库。nginx也需要此库。命令:

yum install -y pcre pcre-devel


三. zlib 安装
zlib 库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip ,所以需要在 Centos 上安装 zlib 库。

yum install -y zlib zlib-devel


四. OpenSSL 安装
OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。
nginx 不仅支持 http 协议,还支持 https(即在ssl协议上传输http),所以需要在 Centos 安装 OpenSSL 库。

yum install -y openssl openssl-devel

2.使用wget命令下载(推荐)。
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz

tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
make
make install

启动 重启 和上面一样

After completion of the above, in the home folder express our new project in mind and then go back to our address nginx configuration (select priority generally default> conf) completed proxy

express project is to be started

npm i  
npm start  
并且localhost:3000
这里要注意! 服务器安全组需要开启3000端口  不然访问不到

Of course, you can use the same method to manage projects pm2

server {
    listen       80; #代理80
    server_name  localhost; #可以换成域名

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    # 代理be  直接到我们的接口路劲
    location /be {
        proxy_pass http://localhost:3000/;

        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Headers Content-Type;
        add_header Access-Control-Allow-Methods POST;
        add_header Access-Control-Allow-Methods GET;
    }

    # 代理网页  直接到我们的home文件夹
    location / {
        root   /home/fe;
        index  index.html index.htm;
    }

Guess you like

Origin www.cnblogs.com/oicb/p/11919213.html