How to configure Nginx reverse proxy with CPanel in CentOS 7

Source: Internet
Author: User
Tags standalone web server symlink cpanel nginx reverse proxy

Guide Nginx is one of the fastest and most powerful WEB servers, known for its high performance and low resource usage. It can be installed either as a standalone Web server or as a reverse proxy Web server. In this article, I will discuss installing Nginx as an Apache reverse proxy server on a Centos 7 server with the CPanel management system installed. Nginx serves as a front-end server with a reverse proxy for static files, and Apache serves as a backend for dynamic files. This setting will improve the performance of the server as a whole.

Let's go through the installation process of configuring Nginx as a reverse proxy on a CentOS 7 x86_64 server that already has CPanel 11.52 installed.

First, we need to install the EPEL library to start this process

First step: Install the EPEL library
[Email protected] [/usr]# yum-y Install epel-releaseloaded plugins:fastestmirror, tsflags, universal-hooksloading mirror speeds from cache D hostfile* ea4:66.23.237.210* base:mirrors.linode.com* extras:mirrors.linode.com* updates: Mirrors.linode.comResolving dependencies--> Running Transaction Check---> Package epel-release.noarch 0:7-5 would Be installed--> finished Dependency resolutiondependencies resolved============================================= =========================================== Package    Arch Version Repository size============================== ==========================================================installing:epel-release noarch 7-5 Extras k
Step Two: Install the Ndeploy centos RPM library to install the Ndeploy centos RPM library to install the Ndeploy Web-class software and Nginx plugin we need
[Email protected] [/usr]# yum-y install http://rpm.piserve.com/nDeploy-release-centos-1.0-1.noarch.rpmLoaded plugins:fastestmirror, Tsflags, universal-hooksndeploy-release-centos-1.0-1.noarch.rpm | 1.7 KB 00:00:00examining/var/tmp/yum-root-ei5twj/ndeploy-release-centos-1.0-1.noarch.rpm: ndeploy-release-centos-1.0-1.noarchmarking/var/tmp/yum-root-ei5twj/ndeploy-release-centos-1.0-1.noarch.rpm to be Installedresolving dependencies--> Running Transaction Check---> Package ndeploy-release-centos.noarch 0:1.0-1 'll be installed--> finished Dependency resolutiondependencies resolved========================================= ===============================================package Arch Version Repository size=============================== =========================================================installing:ndeploy-release-centos Noarch 1.0-1/ Ndeploy-release-centos-1.0-1.noarch 110
Step three: Install Ndeploy and Nginx Ndeploy plugin
[Email protected] [/usr]# yum--enablerepo=ndeploy install Nginx-ndeploy ndeployloaded plugins:fastestmirror, Tsflags, Universal-hooksepel/x86_64/metalink | 9.9 KB 00:00:00epel | 4.3 KB 00:00:00ndeploy | 2.9 KB 00:00:00 (quarter): ndeploy/7/x86_64/primary_db | KB 00:00:00 (2/4): Epel/x86_64/group_gz | 169 KB 00:00:00 (3/4): epel/x86_64/primary_db | 3.7 MB 00:00:02dependencies resolved============================================================================= ===========package Arch Version Repository size=================================================================== =====================installing:ndeploy noarch 2.0-11.el7 ndeploy knginx-ndeploy x86_64 1.8.0-34.el7 NDeploy 36 Minstalling for Dependencies:pyyaml x86_64 3.10-11.el7 Base 153 klibevent x86_64 2.0.21-4.EL7 Base 214 kmemcached x86_64 1 .4.15-9.EL7 base kpython-inotify noarch 0.9.4-4.el7 base kpython-lxml x86_64 3.2.1-4.EL7 Base ry========================================================================================install 2 Packages (+5 Dependent Packages) 

Through these steps, we have completed the installation of Nginx plugin on our server. Now we can configure Nginx as a reverse proxy and create a virtual host for an existing CPanel user account, so we can run the following script.

Fourth step: Start Nginx as the default front-end WEB server and create the default configuration file
[Email protected] [/usr]#/opt/ndeploy/scripts/cpanel-ndeploy-setup.sh enablemodifying Apache http and HTTPS port in CPANELHTTPD restarted Successfully. Created symlink From/etc/systemd/system/multi-user.target.wants/nginx.service to/usr/lib/systemd/system/ nginx.service.Created symlink From/etc/systemd/system/multi-user.target.wants/ndeploy_watcher.service to/usr/lib/ systemd/system/ndeploy_watcher.service.created symlink From/etc/systemd/system/multi-user.target.wants/ndeploy_ Backends.service To/usr/lib/systemd/system/ndeploy_backends.service.confgen:: Saheethaconfgen:: SATest

You can see that this script will modify the Apache port from 80 to another port to let Nginx act as a front-end WEB server and create a virtual host profile for an existing CPanel user. Once completed, confirm the status of Apache and Nginx.

Apache Status:
[Email protected] [/var/run/httpd]# systemctl status httpd httpd.service-apache Web serverloaded:loaded (/usr/lib/systemd/system/httpd . Service; Enabled Vendor preset:disabled) active:active (running) since Mon 2016-01-18 06:34:23 UTC; 12s agoprocess:25606 execstart=/usr/sbin/apachectl Start (code=exited, status=0/success) Main pid:24760 (httpd) CGroup: /system.slice/httpd.service? 24760/usr/local/apache/bin/httpd-k Startjan 06:34:23 server1.centos7-test.com systemd[1]: Starting Apache Web Server ... Jan 06:34:23 server1.centos7-test.com apachectl[25606]: httpd (PID 24760) already Runningjan 06:34:23 7-test.com systemd[1]: Started Apache Web Server.
Nginx Status:
 [email protected] [~]# systemctl status Nginx nginx.service-nginx-ndeploy-high performance Web serverLoaded : Loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset:disabled) active:active (running) since Sun 2016 -01-17 17:18:29 UTC; 13h agodocs:http://nginx.org/en/docs/main pid:3833 (nginx) CGroup:/system.slice/nginx.service├─3833 nginx:master Process/usr/sbin/nginx-c/etc/nginx/nginx.conf├─25473 nginx:worker process├─25474 nginx:worker process└─25475 nginx: Cache Manager Processjan 17:18:29 server1.centos7-test.com systemd[1]: Starting nginx-ndeploy-high performance Web SE RVer ... Jan 17:18:29 server1.centos7-test.com nginx[3804]: nginx:the configuration file/etc/nginx/nginx.conf syntax is OkJan 17:18:29 server1.centos7-test.com nginx[3804]: nginx:configuration file/etc/nginx/nginx.conf test is SuccessfulJan 1 7 17:18:29 server1.centos7-test.com systemd[1]: Started nginx-ndeploy-high Performance Web server. 

Nginx is running as a front-end server on port 80, and the Apache configuration is changed to listen on HTTP port 9999 and HTTPS Port 4430. Please look at their situation:

[Email protected] [/usr/local/src]# Netstat-plan | grep httpdtcp 0 0 0.0.0.0:4430 0.0.0.0:* LISTEN 17270/httpdtcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 17270/httpdtcp6 0 0::: 44 -:::* LISTEN 17270/httpdtcp6 0 0::: 9999:::* LISTEN 17270/httpd

[Email protected] [/usr/local/src]# Netstat-plan | grep nginxtcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 17802/nginx:mastertcp 0 0 45.79.183.73:80 0.0.0.0:* LISTEN 17802/nginx:m Aster

The configuration file for a virtual host created for an existing user is "/etc/nginx/sites-enabled". This file path contains the Nginx main configuration file.

[Email protected] [/etc/nginx/sites-enabled]# ll | grep. conf-rw-r--r--1 root root 311 Jan 09:02 saheetha.com.conf-rw-r--r--1 root root 336 Jan 09:02 saheethastest.c Om.conf
example virtual host for a domain name:
server {listen 45.79.183.73:80; #CPIPVSIX: 80;# servernamesserver_name saheetha.com www.saheetha.com;access_log/usr/ Local/apache/domlogs/saheetha.com Main;access_log/usr/local/apache/domlogs/saheetha.com-bytes_log Bytes_log; Include/etc/nginx/sites-enabled/saheetha.com.include;}

We can start the browser to view the Web site to determine the working status of the Web server. After you install, read the Web service information on the server.

[Email protected] [/home]# IP A | Grep-i eth03:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000inet 45.79.183.73 /24 BRD 45.79.183.255 Scope Global Dynamic Eth0[email protected] [/home]# Nginx-vnginx version:nginx/1.8.0

Nginx will create a virtual host for any account that is newly created in CPanel. With these simple steps, we are able to configure Nginx as a reverse proxy on a CentOS 7/cpanel server.

the advantages of Nginx as a reverse proxy
    1. Easy to install and configure.
    2. High efficiency and good performance.
    3. Prevent Ddos attacks.
    4. supports the use of. htaccess as a rewrite rule for PHP.

I hope this article will be of use to you. Thank you for looking at it. I am very pleased to receive your valuable comments and suggestions and to further improve.

Originally from: http://www.linuxprobe.com/centos-cpanel-nginx.html

How to configure Nginx reverse proxy with CPanel in CentOS 7

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.