CentOS 7 installs Nginx as a reverse proxy
Title
You need to use the reverse proxy function of nginx. The test environment is centos+NGINX 1.8.0.
<code>跳过一些繁琐的问题,直接记录核心 </code>
Steps
<code>(1)centos 安装在VM中,因此需要注意网络连接问题 (2)安装nginx使用的是具有网络的yum功能 (3)配置centos防火墙,需要开启80 端口 (4)nginx 反向代理配置 (5)性能优化设置(后续工作...) </code>
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>
Execute the command:
<code>yum install nginx service nginx start </code>
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>
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>
After enabling iptables, you need to set the port and access rules.
<code>(1)编辑 /etc/sysconfig/iptables (2)清空规则 (3)添加需要的规则 </code>
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>
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>
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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

Steps to stop Nginx from the command line: 1. Find the Nginx process ID (PID); 2. Use the kill or systemctl command to stop the Nginx process with PID; 3. Verify that Nginx is stopped by using ps -ef | grep nginx to check the Nginx process.

Steps to start Nginx in Linux: Check whether Nginx is installed. Use systemctl start nginx to start the Nginx service. Use systemctl enable nginx to enable automatic startup of Nginx at system startup. Use systemctl status nginx to verify that the startup is successful. Visit http://localhost in a web browser to view the default welcome page.

The server does not have permission to access the requested resource, resulting in a nginx 403 error. Solutions include: Check file permissions. Check the .htaccess configuration. Check nginx configuration. Configure SELinux permissions. Check the firewall rules. Troubleshoot other causes such as browser problems, server failures, or other possible errors.

Resolve Nginx 499 error: The Nginx 499 error indicates that the client closes the connection before the server processes the request, which is usually caused by a client timeout or a connection interruption. Solutions include: checking client timeout settings; improving server flow limits; checking load balancer configuration; optimizing server response time; enabling KeepAlive; checking firewall rules; and contacting network service providers.

In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.

To shut down the Nginx service, follow these steps: Determine the installation type: Red Hat/CentOS (systemctl status nginx) or Debian/Ubuntu (service nginx status) Stop the service: Red Hat/CentOS (systemctl stop nginx) or Debian/Ubuntu (service nginx stop) Disable automatic startup (optional): Red Hat/CentOS (systemctl disabled nginx) or Debian/Ubuntu (syst

Question: How to start Nginx? Answer: Install Nginx Startup Nginx Verification Nginx Is Nginx Started Explore other startup options Automatically start Nginx
