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

WeChat applet implements a simple dice game

This article shares the specific code of the WeCh...

Docker installs redis 5.0.7 and mounts external configuration and data issues

Redis is an open source NoSQL database written in...

Practical way to build selenium grid distributed environment with docker

Recently, I needed to test the zoom video confere...

A Deeper Look at SQL Injection

1. What is SQL injection? Sql injection is an att...

A brief analysis of MySQL parallel replication

01 The concept of parallel replication In the mas...

How to install elasticsearch and kibana in docker

Elasticsearch is very popular now, and many compa...

How to use Docker to build OpenLDAP+phpLDAPadmin unified user authentication

1. Background Use LDAP to centrally manage operat...

How to play local media (video and audio) files using HTML and JavaScript

First of all, for security reasons, JavaScript ca...

Goodbye Docker: How to Transform to Containerd in 5 Minutes

Docker is a very popular container technology. Th...

jQuery plugin to implement minesweeper game (3)

This article shares the third article on how to u...

Install Docker on Centos7 (2020 latest version available, just copy and paste)

Refer to the official documentation here for oper...

How to add a paging navigation bar to the page through Element UI

need Add a paging bar, which can jump to the page...

Linux operation and maintenance basic swap partition and lvm management tutorial

Table of contents 1. Swap partition SWAP 1.1 Crea...