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

Two usages of iFrame tags in HTML

I have been working on a project recently - Budou...

Example of how rem is adapted for mobile devices

Preface Review and summary of mobile terminal rem...

JavaScript data visualization: ECharts map making

Table of contents Overview Precautions 1. Usage 2...

Will css loading cause blocking?

Maybe everyone knows that js execution will block...

What are the benefits of semantic HTML structure?

one: 1. Semantic tags are just HTML, there is no ...

Summary of several common logs in MySQL

Preface: In the MySQL system, there are many diff...

A complete guide to Linux environment variable configuration

Linux environment variable configuration When cus...

How to connect Navicat to the docker database on the server

Start the mysql container in docekr Use command: ...

Sample code for partitioning and formatting a disk larger than 20TB on centos6

1. Server environment configuration: 1. Check dis...

Use HTML and CSS to create your own warm man "Dabai"

The final result is like this, isn’t it cute… PS:...

How to configure Jupyter notebook in Docker container

Jupyter notebook is configured under the docker c...

A small problem about null values ​​in MySQL

Today, when testing the null value, I found a sma...