Nginx proxy forwarding implementation code uploaded by Alibaba Cloud OSS

Nginx proxy forwarding implementation code uploaded by Alibaba Cloud OSS

Preface

Because the mini program upload requires https, the server https uses the certificate generated by letsencrypt, but Alibaba Cloud OSS does not do https (too lazy to upload the certificate), so I thought of using Nginx proxy to forward the upload request.

Nginx Configuration

# HTTPS server
#
 server {
  listen 443 ssl;
  server_name your.domain.name;

  ...

  location / {
    proxy_pass http://127.0.0.1:3000;
    proxy_set_header Host $Host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For 
  }

  location /oss {
    proxy_set_header Host drift-book-dev.oss-cn-shenzhen.aliyuncs.com;
    proxy_set_header Connection keep-alive;
    proxy_pass http://***.oss-cn-***.aliyuncs.com/;
    #proxy_set_header X-Real-IP $remote_addr;
    #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
 }

Here, the sub-path "/oss" is used as the forwarding path.

proxy_pass specifies your Alibaba Cloud domain name. Remember to add a slash "/" at the end, otherwise the forwarding will fail.

nginx configure proxy_pass proxy forwarding

Assume the following four situations are accessed using http://192.168.1.1/proxy/test.html respectively.

The first one:

location /proxy/ { 
  proxy_pass http://127.0.0.1/; 
} 

Proxy to URL: http://127.0.0.1/test.html

The second type (compared to the first type, with one less / at the end)

location /proxy/ { 
  proxy_pass http://127.0.0.1; 
} 

Proxy to URL: http://127.0.0.1/proxy/test.html

The third type:

location /proxy/ { 
  proxy_pass http://127.0.0.1/aaa/; 
} 

Proxy to URL: http://127.0.0.1/aaa/test.html

The fourth type (compared to the third type, with one less / at the end)

location /proxy/ { 
  proxy_pass http://127.0.0.1/aaa; 
} 

Proxy to URL: http://127.0.0.1/aaatest.html

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Nginx using proxy forwarding request example
  • Nginx reverse proxy is used for intranet domain name forwarding
  • Nginx server as reverse proxy to implement URL forwarding configuration in internal LAN

<<:  MySQL 5.7.17 installation and configuration method graphic tutorial (windows10)

>>:  How to solve jQuery conflict problem

Recommend

javascript countdown prompt box

This article example shares the specific code of ...

Detailed explanation of how to implement secondary cache with MySQL and Redis

Redis Introduction Redis is completely open sourc...

The concept and characteristics of MySQL custom variables

A MySQL custom value is a temporary container for...

HTML table tag tutorial (32): cell horizontal alignment attribute ALIGN

In the horizontal direction, you can set the cell...

Solve the error "Can't locate ExtUtils/MakeMaker.pm in @INC"

When installing mha4mysql, the steps are roughly:...

Vue practice of preventing multiple clicks

Generally, click events will be divided into diff...

How to configure Nginx load balancing

Table of contents Nginx load balancing configurat...

Detailed explanation of the integer data type tinyint in MySQL

Table of contents 1.1Tinyint Type Description 1.2...

JS implements simple addition and subtraction of shopping cart effects

This article example shares the specific code of ...

How a select statement is executed in MySQL

Table of contents 1. Analyzing MySQL from a macro...

Analyzing the MySql CURRENT_TIMESTAMP function by example

When creating a time field DEFAULT CURRENT_TIMEST...

Usage and description of HTML tag tbody

The tbody element should be used in conjunction wi...