nodejs+nginx给远程服务器配置反向代理部署多个域名

在阿里云上购买了一个域名,例如mine.com,现在想在远程服务器上部署两个微信公众号项目,wechat1和wechat2,域名分别为wechat1.mine.comwechat2.mine.com(端口均为80),分别指向mine.com:70mine.com:90
(因为微信公众平台服务器url以http开头的只支持80)

工具PuTTY、电脑

  1. 打开putty,输入IP地址/域名、端口号
    在这里插入图片描述

  2. 输入用户名和密码进入根目录,你想把文件放在那里,就进到该路径,我文件的存放路径是根目录下的 /usr/local/src/
    在这里插入图片描述

  3. 下载安装nginx及相关组件,命令如下

      1、openssl ——  ssl 功能需要openssl库
    

    [root@iuynskfw5dfgsff src]# wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz
    [root@iuynskfw5dfgsff src]# tar zxvf openssl-fips-2.0.10.tar.gz
    [root@iuynskfw5dfgsff src]# cd openssl-fips-2.0.10
    [root@iuynskfw5dfgsff openssl-fips-2.0.10]# ./config && make && make install

     2、pcre	——   rewrite模块需要 pcre 库
    

    [root@iuynskfw5dfgsff src]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz
    [root@iuynskfw5dfgsff src]# tar zxvf pcre-8.40.tar.gz
    [root@iuynskfw5dfgsff src]# cd pcre-8.40
    [root@iuynskfw5dfgsff pcre-8.40]# ./configure && make && make install

    3、zlib ——  gzip模块需要 zlib 库
    

    [root@iuynskfw5dfgsff src]# wget http://zlib.net/zlib-1.2.11.tar.gz
    [root@iuynskfw5dfgsff src]# tar zxvf zlib-1.2.11.tar.gz
    [root@iuynskfw5dfgsff src]# cd zlib-1.2.11
    [root@iuynskfw5dfgsff zlib-1.2.11]# ./configure && make && make install

    4、nginx	
    

    [root@iuynskfw5dfgsff src]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
    [root@iuynskfw5dfgsff src]# tar zxvf nginx-1.10.2.tar.gz
    [root@iuynskfw5dfgsff src]# cd nginx-1.10.2
    [root@iuynskfw5dfgsff nginx-1.10.2]# ./configure && make && make install

  4. 配置
    进入/usr/local/nginx/conf,并打开nginx.conf,找到如下代码

server {
        #nginx的监听端口
        listen       80; 
        #这里是请求域名
        server_name  localhost;    改为   server_name  wechat1.mine.com;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
             #-----再此新增 如下代码proxy_pass 后 可写域名/IP  --------
              proxy_pass http://mine.com:70;  #请求转发到哪里
          # root   html;
         # index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

将上面代码复制一遍粘贴到它后面,将server_name 改为 wechat2.mine.com


server {
        #nginx的监听端口
        listen       80; 
        #这里是请求域名
        server_name  localhost;    改为   server_name  wechat2.mine.com;
        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
             #-----再此新增 如下代码proxy_pass 后 可写域名/IP  --------
              proxy_pass http://mine.com:90;  #请求转发到哪里
          # root   html;
         # index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
  1. 检查配置是否正确
    /usr/local/nginx/sbin/nginx -t
    执行后,如果正确则会输出结尾为ok和successful的两句话,如果报错则根据错误修改。

  2. 启动nginx
    首先,通过whereis nginx确定 nginx 安装到了哪里;
    然后,进入该目录;
    在这里插入图片描述
    最后通过 /usr/local/nginx/sbin/nginx 启动nginx
    如果什么都没输出则启动成功,否则会输出错误信息。
    参考文档1 参考文档2

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值