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

A detailed introduction to the use of block comments in HTML

Common comments in HTML: <!--XXXXXXXX-->, wh...

Implementation of Vue package size optimization (from 1.72M to 94K)

1. Background I recently made a website, uidea, w...

Analysis of parameter transfer process of driver module in Linux

Declare the parameter name, type and permission y...

Vue project realizes login and registration effect

This article example shares the specific code of ...

The final solution to Chrome's minimum font size limit of 12px

I believe that many users who make websites will ...

MySQL 8.0.12 Installation and Configuration Tutorial

This article records the detailed tutorial for in...

Master-slave synchronization configuration of Mysql database

Table of contents Mysql master-slave synchronizat...

Record a pitfall of MySQL update statement update

background Recently, I executed a DML statement d...

MySQL Index Optimization Explained

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

Vue3 Vue Event Handling Guide

Table of contents 1. Basic event handling 2. Send...

25 Examples of Using Circular Elements in Web Design

Today, this post lists some great examples of circ...