Setting up a proxy server using nginx

Setting up a proxy server using nginx

Nginx can use its reverse proxy function to implement load balancing, and can also use its forward proxy function to set up a proxy server. For example, in an intranet environment, run nginx as a proxy server on a machine that can connect to the Internet. Other machines can connect to the Internet through this machine by setting its IP and port. This article uses the official nginx image, and the proxy server can be easily implemented through the following steps.

Step 1: Start nginx

[root@devops ~]# docker run -p 8888:8888 --name proxy-nginx -d nginx
c7baab8ea9da0a148aa9bcc1295a54391906f6be94efca7189df23ceecdbf714
[root@devops ~]#

Step 2: Set up nginx

Enter the container

[root@devops ~]# docker exec -it proxy-nginx sh

update apt-get

Install ping/vi/ps: apt-get update; apt-get install procps vim inetutils-ping

Set up nginx.conf

Add the following content to achieve the simplest proxy function

  resolver 8.8.8.8;
  server {
    listen 8888;
    location / {
      proxy_pass http://$http_host$request_uri;
    }
  }

The rest of the information is the confirmed content of nginx.conf and has not been modified.

# cat nginx.conf
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
  worker_connections 1024;
}
http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;
  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';
  access_log /var/log/nginx/access.log main;
  sendfile on;
  #tcp_nopush on;
  keepalive_timeout 65;
  #gzip on;
  resolver 8.8.8.8;
  server {
    listen 8888;
    location / {
      proxy_pass http://$http_host$request_uri;
    }
  }
  include /etc/nginx/conf.d/*.conf;
}
#

Step 4: Set up the client

Set the server IP and the above port 8888 on the client, and you can connect to the network through the proxy server.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • CentOS 7.2 builds nginx web server to deploy uniapp project
  • Implementation of deploying vue project to nginx/tomcat server
  • Linux server nginx uninstall and installation tutorial
  • Solution to nginx hiding version number and WEB server information
  • Detailed explanation of Nginx server load balancing strategy (6 types)
  • How to configure nginx to ensure that the frps server and web share port 80
  • How to configure multiple domain names on one nginx server
  • How to implement dynamic automatic up and down of upstream servers without reload based on nginx

<<:  Detailed explanation of MySQL 5.7.9 shutdown syntax example

>>:  Use Javascript to develop sliding-nav navigation plug-in with sliding bar effect

Recommend

How to use Nginx to realize the coexistence of multiple containers in the server

background There is a Tencent Linux cloud host, o...

Solution to the garbled code problem in MySQL 5.x

MySQL is a commonly used open source database sof...

VUE implements bottom suction button

This article example shares the specific code of ...

How to use CSS attribute selectors to splice HTML DNA

CSS attribute selectors are amazing. They can hel...

Vue detailed explanation of mixins usage

Table of contents Preface 1. What are Mixins? 2. ...

Detailed explanation of MySQL Explain

In daily work, we sometimes run slow queries to r...

Three ways to achieve text flashing effect in CSS3 Example code

1. Change the transparency to achieve the gradual...

Summary of Git commit log modification methods

Case 1: Last submission and no push Execute the f...

Detailed installation and configuration of Subversion (SVN) under Ubuntu

If you are a software developer, you must be fami...

Vue state management: using Pinia instead of Vuex

Table of contents 1. What is Pinia? 2. Pinia is e...

Understanding MySQL clustered indexes and how clustered indexes grow

In this note, we briefly describe What is the B+T...

Design perspective technology is an important capital of design ability

A design soldier asked: "Can I just do pure ...

Example of how to deploy Spring Boot using Docker

Here we mainly use spring-boot out of the box, wh...