溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Nginx反向代理一個(gè)80端口下配置多個(gè)微信的方法

發(fā)布時(shí)間:2022-04-29 15:40:53 來(lái)源:億速云 閱讀:349 作者:iii 欄目:大數(shù)據(jù)

這篇文章主要介紹“Nginx反向代理一個(gè)80端口下配置多個(gè)微信的方法”的相關(guān)知識(shí),小編通過(guò)實(shí)際案例向大家展示操作過(guò)程,操作方法簡(jiǎn)單快捷,實(shí)用性強(qiáng),希望這篇“Nginx反向代理一個(gè)80端口下配置多個(gè)微信的方法”文章能幫助大家解決問(wèn)題。

nginx反向代理一個(gè)80端口下配置多個(gè)微信項(xiàng)目詳解

 我們要接入微信公眾號(hào)平臺(tái)開(kāi)發(fā),需要填寫(xiě)服務(wù)器配置,然后依據(jù)接口文檔才能實(shí)現(xiàn)業(yè)務(wù)邏輯。但是微信公眾號(hào)接口只支持80接口(80端口)。我們因業(yè)務(wù)需求需要在一個(gè)公眾號(hào)域名下面,發(fā)布兩個(gè)需要微信授權(quán)的項(xiàng)目,怎么辦?

  我們可以用nginx服務(wù)器做反向代理來(lái)解決這個(gè)問(wèn)題。nginx服務(wù)器對(duì)外80端口,然后根據(jù)url參數(shù)不同,對(duì)內(nèi)訪問(wèn)不同的項(xiàng)目。

  Nginx反向代理一個(gè)80端口下配置多個(gè)微信的方法

  nginx配置如下:

  打開(kāi)/usr/local/nginx/conf/nginx.conf

worker_processes 4;
error_log logs/error.log;
events {
  worker_connections 1024;
}
http {
  include    mime.types;
  default_type application/octet-stream;
  sendfile    on;
  keepalive_timeout 65;

gzip on;
gzip_min_length 1k;
gzip_buffers 16 64k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
gzip_vary on;

  #指向項(xiàng)目一
  upstream backend1 {
    server 192.168.1:8081;
  }
  #指向項(xiàng)目二
  upstream backend2{
    192.168.1.1:8082;
  }
  proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:128m inactive=1d max_size=1g;
  include vhosts/*;
}

  打開(kāi)/usr/local/reverse_proxy_nginx/conf/nginx.conf

worker_processes 2;
events {
  worker_connections 1024;
}
http {
  include    mime.types;
  default_type application/octet-stream;
  access_log /home/nginx_log/reverse_proxy_no1_access.log;
  sendfile    on;
  keepalive_timeout 65;
  upstream backend1 {
    #server 192.168.1.1:8181;
  server 192.168.1.1:8081;
  }
  upstream backend2 {
    #server 192.168.1.1:8082;
  server 192.168.1.1:8082;
  }
  proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:128m inactive=30m max_size=1g;
  server {
    listen    8081;
    server_name h5.xxxx.com;

    location / {
        proxy_pass http://backend1;
      #proxy settings
        proxy_redirect   off;
       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_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
      proxy_max_temp_file_size 0;
      proxy_connect_timeout   90;
      proxy_send_timeout     90;
      proxy_read_timeout     90;
      proxy_buffer_size     4k;
      proxy_buffers       4 32k;
      proxy_busy_buffers_size  64k;
      proxy_temp_file_write_size 64k;
    add_header nginx-res "http://backend1";
    }

    location ~ ^/(h5)(.*)$ { 
       proxy_pass http://backend2;
       proxy_redirect off;
       proxy_set_header host $host;
       proxy_cache cache;
       proxy_cache_valid 200 302 1d;
       proxy_cache_valid 301 1d;
       proxy_cache_valid any 1m;
       expires 1h;
     add_header nginx-res "http://backend2";
       proxy_ignore_headers "cache-control" "expires" "set-cookie";
       add_header nginx-cache "$upstream_cache_status";
     }

    
    error_page  500 502 503 504 /50x.html;
    location = /50x.html {
      root  html;
    }
  location ~ .*\.(gif|jpg|png|css|js|ico)(.*) {
       proxy_pass http://backend1;
       proxy_redirect off;
       proxy_set_header host $host;
       proxy_cache cache;
       proxy_cache_valid 200 302 30d;
       proxy_cache_valid 301 1d;
       proxy_cache_valid any 1m;
       expires 30d;
       proxy_ignore_headers "cache-control" "expires" "set-cookie";
     add_header nginx-res "http://backend1";
       add_header nginx-cache "$upstream_cache_status";
    }

關(guān)于“Nginx反向代理一個(gè)80端口下配置多個(gè)微信的方法”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注億速云行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI