Table of Contents
Title
Steps
implementation
Summary:
Home Backend Development PHP Tutorial CentOS 7 installs Nginx as a reverse proxy

CentOS 7 installs Nginx as a reverse proxy

Jul 30, 2016 pm 01:31 PM
centos iptables nginx proxy

Title

You need to use the reverse proxy function of nginx. The test environment is centos+NGINX 1.8.0.

<code>跳过一些繁琐的问题,直接记录核心
</code>
Copy after login

Steps

<code>(1)centos 安装在VM中,因此需要注意网络连接问题
(2)安装nginx使用的是具有网络的yum功能
(3)配置centos防火墙,需要开启80 端口
(4)nginx 反向代理配置
(5)性能优化设置(后续工作...)
</code>
Copy after login

implementation

1. Install nginx with yum
First add the nginx source and test using the latest nginx 1.8.0

<code>rpm -ivh  http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm 
</code>
Copy after login

Execute the command:

<code>yum install nginx
service nginx start
</code>
Copy after login

If nothing goes wrong, enter 127.0.0.1:80 in the browser and you will see the nginx welcome interface.

2. Check the configuration of nginx

<code>rpm -ql nginx
此命令可以查看nginx的配置信息
</code>
Copy after login

3. Close the firewall and configure iptables

centos uses firewall to configure ports and networks by default, but most of the online information now uses iptables. In view of the sufficient information, iptalbes is used instead.

Static firewall rules using iptables and ip6tables
If you want to use your own iptables and ip6tables static firewall rules, then please install iptables-services and disable firewalld, enable iptables and ip6tables:

<code>yum install iptables-services
systemctl mask firewalld.service
systemctl enable iptables.service
systemctl enable ip6tables.service
</code>
Copy after login

After enabling iptables, you need to set the port and access rules.

<code>(1)编辑  /etc/sysconfig/iptables
(2)清空规则
(3)添加需要的规则
</code>
Copy after login

Example:

# Allow established or connected traffic
-A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
#Allow local loopback interface
-A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
#Allow external access to this machine
-A OUTPUT -j ACCEPT
# Allow access to the SSH port. If the port is modified, you can change the corresponding port number
-A INPUT -p tcp –dport 22 -j ACCEPT
#Allow access to port 80 (HTTP)
-A INPUT -p tcp –dport 80 -j ACCEPT
#Allow access to FTP ports: 21, 20
-A INPUT -p tcp –dport 21 -j ACCEPT
-A INPUT -p tcp –dport 20 -j ACCEPT
#Allow access to port 161 (SNMP):
-A INPUT -p udp –dport 161 -j ACCEPT


Based on the above configuration, websites can be accessed from each other in the LAN.

4. Configure the reverse proxy function of nginx

<code>本次只是使用反向代理功能,因此nginx的负载均衡功能就不涉及。
</code>
Copy after login

The reverse proxy function uses the proxy_pass and sub_filter modules

<code>location / {
    proxy_pass  需要代理的IP;

    #Proxy Settings
    proxy_redirect     off;
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for
    proxy_max_temp_file_size 0;
    proxy_connect_timeout      90;
    proxy_send_timeout         90;
    proxy_read_timeout         90;
    proxy_buffer_size          4k;
    proxy_buffers              4 32k;
    proxy_busy_buffers_size    64k;
    proxy_temp_file_write_size 64k;
# 做反向代理时候,出现ip地址直接跳转,没有是使用代理IP ,是因为需要使用sub_filter.
sub_filter 需要代理的IP  nginx的本机服务器;
sub_filter_once off;    
   }
</code>
Copy after login

Summary:

nginx reverse proxy concept is relatively simple and easy to configure. The next step is to proceed Do a stress test to see the actual effect.


[1]http://www.centoscn.com/CentOS/Intermediate/2015/0313/4879.html Using iptables

[2]http://www.centoscn.com/CentOS/2013/0413/ 293.html Configure iptables ports and rules

[3]http://www.nginx.cn/927.html Reverse proxy

[4]http://zhaochen.blog.51cto.com/2029597/379233/

[5]https://github.com/yaoweibin/ngx_http_substitutions_filter_module

[6]http://www.xxorg.com/archives/3608

Copyright statement: This article is an original article by the blogger and has not been authorized by the author. Reprinting is not allowed with the permission of the blogger.

The above introduces the installation of Nginx as a reverse proxy on CentOS 7, including the relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1263
29
C# Tutorial
1237
24
How to start containers by docker How to start containers by docker Apr 15, 2025 pm 12:27 PM

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

Centos shutdown command line Centos shutdown command line Apr 14, 2025 pm 09:12 PM

The CentOS shutdown command is shutdown, and the syntax is shutdown [Options] Time [Information]. Options include: -h Stop the system immediately; -P Turn off the power after shutdown; -r restart; -t Waiting time. Times can be specified as immediate (now), minutes ( minutes), or a specific time (hh:mm). Added information can be displayed in system messages.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to optimize CentOS HDFS configuration How to optimize CentOS HDFS configuration Apr 14, 2025 pm 07:15 PM

Improve HDFS performance on CentOS: A comprehensive optimization guide to optimize HDFS (Hadoop distributed file system) on CentOS requires comprehensive consideration of hardware, system configuration and network settings. This article provides a series of optimization strategies to help you improve HDFS performance. 1. Hardware upgrade and selection resource expansion: Increase the CPU, memory and storage capacity of the server as much as possible. High-performance hardware: adopts high-performance network cards and switches to improve network throughput. 2. System configuration fine-tuning kernel parameter adjustment: Modify /etc/sysctl.conf file to optimize kernel parameters such as TCP connection number, file handle number and memory management. For example, adjust TCP connection status and buffer size

Difference between centos and ubuntu Difference between centos and ubuntu Apr 14, 2025 pm 09:09 PM

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

How to create containers for docker How to create containers for docker Apr 15, 2025 pm 12:18 PM

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

Centos configuration IP address Centos configuration IP address Apr 14, 2025 pm 09:06 PM

Steps to configure IP address in CentOS: View the current network configuration: ip addr Edit the network configuration file: sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 Change IP address: Edit IPADDR= Line changes the subnet mask and gateway (optional): Edit NETMASK= and GATEWAY= Lines Restart the network service: sudo systemctl restart network verification IP address: ip addr

What are the common misunderstandings in CentOS HDFS configuration? What are the common misunderstandings in CentOS HDFS configuration? Apr 14, 2025 pm 07:12 PM

Common problems and solutions for Hadoop Distributed File System (HDFS) configuration under CentOS When building a HadoopHDFS cluster on CentOS, some common misconfigurations may lead to performance degradation, data loss and even the cluster cannot start. This article summarizes these common problems and their solutions to help you avoid these pitfalls and ensure the stability and efficient operation of your HDFS cluster. Rack-aware configuration error: Problem: Rack-aware information is not configured correctly, resulting in uneven distribution of data block replicas and increasing network load. Solution: Double check the rack-aware configuration in the hdfs-site.xml file and use hdfsdfsadmin-printTopo

See all articles