Use nginx reverse proxy, configure multiple WeChat projects under port 80, nginx80

Source: Internet
Author: User

Use nginx reverse proxy. Under port 80, configure multiple projects, nginx80

To access the public account platform for development, we need to fill in the server configuration, and then follow the interface documentation to implement business logic. HoweverThe public account interface only supports port 80). What should we do if we release two projects that require authorization under a public domain name due to business needs?

We can use the nginx server as a reverse proxy to solve this problem. The nginx server Accesses Different projects internally Based on the URL parameters of port 80.

  

The nginx configuration is as follows:

Open/usr/local/nginx/conf/nginx. conf

1 worker_processes 4; 2 error_log logs/error. log; 3 events {4 worker_connections 1024; 5} 6 http {7 include mime. types; 8 default_type application/octet-stream; 9 sendfile on; 10 keepalive_timeout 65; 11 12 gzip on; 13 gzip_min_length 1 k; 14 gzip_buffers 16 64 k; 15 gzip_http_version 1.1; 16 gzip_comp_level 6; 17 gzip_types text/plain application/x-javascript text/css application/xml application/javascript; 18 gzip_vary on; 19 20 # point to project 1 21 upstream backend1 {22 server 192.168.1: 8081; 23} 24 # point to project 2 25 upstream backend2 {26 192.168.1.1: 8082; 27} 28 proxy_cache_path/tmp/cache levels = keys_zone = cache: 128 m inactive = 1d max_size = 1G; 29 include vhosts/*; 30}View Code

Open/usr/local/reverse_proxy_nginx/conf/nginx. conf

1 worker_processes 2; 2 events {3 worker_connections 1024; 4} 5 http {6 include mime. types; 7 default_type application/octet-stream; 8 access_log/home/nginx_log/reverse_proxy_no1_access.log; 9 sendfile on; 10 keepalive_timeout 65; 11 upstream backend1 {12 # server 192.168.1.1: 8181; 13 server 192.168.1.1: 8081; 14} 15 upstream backend2 {16 # server 192.168.1.1: 8082; 17 server 192.168.1.1: 8082; 18} 19 pro Xy_cache_path/tmp/cache levels = keys_zone = cache: 128 m inactive = 30 m max_size = 1G; 20 server {21 listen 8081; 22 server_name h5.xxxx.com; 23 24 location/{25 proxy_pass http: // backend1; 26 # Proxy Settings27 proxy_redirect off; 28 proxy_set_header Host $ host; 29 proxy_set_header X-Real-IP $ remote_addr; 30 proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for; 31 proxy_next_upstream error timeout inv Alid_header http_500 http_502 http_503 http_504; 32 bytes 0; 33 proxy_connect_timeout 90; 34 proxy_send_timeout 90; 35 bytes 90; 36 bytes 4 k; 37 proxy_buffers 4 32 k; 38 bytes 64 k; 39 proxy_temp_file_write_size 64 k; 40 add_header Nginx-Res "http: // backend1"; 41} 42 43 location ~ ^/(H5 )(. *) ${44 proxy_pass http: // backend2; 45 proxy_redirect off; 46 proxy_set_header Host $ host; 47 proxy_cache; 48 proxy_cache_valid 200 1d; 49 proxy_cache_valid 302 1d; 50 proxy_cache_valid any 1 m; 51 expires 1 h; 52 add_header Nginx-Res "http: // backend2"; 53 proxy_ignore_headers "Cache-Control" Expires "" Set-Cookie "; 54 add_header Nginx-Cache "$ upstream_cache_status"; 55} 56 57 58 error_page 500 502 503 504/50 x.html; 59 location =/50x.html {60 root html; 61} 62 location ~. *\. (Gif | jpg | png | css | js | ico )(. *) {63 proxy_pass http: // backend1; 64 proxy_redirect off; 65 proxy_set_header Host $ host; 66 proxy_cache cache; 67 proxy_cache_valid 200 302 30d; 68 proxy_cache_valid 301 1d; 69 proxy_cache_valid any 1 m; 70 expires 30d; 71 proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; 72 add_header Nginx-Res "http: // backend1 "; 73 add_header Nginx-Cache "$ upstream_cache_status"; 74}View Code

When we open the URL containing h5, it will jump to the 8081 port project, but it is still port 80. Therefore, two projects can simultaneously implement authorized logon.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.