Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to configure Nginx reverse proxy with cPanel in CentOS 7

2025-04-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article Xiaobian introduces in detail for you "how to use cPanel to configure Nginx reverse proxy in CentOS 7", the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use cPanel to configure Nginx reverse proxy in CentOS 7" can help you solve your doubts.

CPanel is the most powerful, easy-to-use and most popular virtual host control system in the world. Many foreign hosts use this control panel.

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

Step 1: install the EPEL library

Root@server1 [/ usr] # yum-y install epel-releaseLoaded plugins: fastestmirror, tsflags Universal-hooksLoading mirror speeds from cached 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 will be installed-- > Finished Dependency ResolutionDependencies Resolved= Package Arch Version Repository Size=Installing:epel-release noarch 7-5 extras 14k step 2: install nDeploy's CentOS RPM library you can install nDeploy's CentOS RPM library to install what we need NDeploy Web software and Nginx plug-in root@server1 [/ 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 kB 00:00:00Examining 1.0 -1 will 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 3: install the nDeploy and Nginx nDeploy plug-ins

Root@server1 [/ 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 (1 kB 4): ndeploy/7/x86_64/primary_db | 14 kB 00:00:00 (2 kB 4): epel/x86_64/group_gz | 169 kB 00:00:00 (3 MB 00:00:02Dependencies Resolved=Package Arch Version Repository Size=Installing:nDeploy noarch 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 80 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 x 86'64 1.4.15-9.el7 base 84 kpython-inotify noarch 0.9.4-4.el7 base 49 kpython-lxml x86'64 3.2.1-4.el7 base 758 kTransaction Summary=Install 2 Packages (+ 5 Dependent packages)

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

Step 4: start Nginx as the default front-end Web server and create a default configuration file

Root@server1 [/ 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 port of Apache from 80 to another port to make Nginx the front-end Web server and create a virtual host profile for existing cPanel users. Once complete, confirm the status of Apache and Nginx.

Apache status:

Root@server1 [/ 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 usr/local/apache/bin/httpd 24760 / usr/local/apache/bin/httpd-k startJan 18 06:34:23 server1.centos7-test.com systemd [1]: Starting Apache Web Server...Jan 18 06:34:23 server1.centos7-test.com apachectl [25606]: httpd (pid 24760) already runningJan 18 06:34:23 server1.centos7-test.com systemd [1]: Started Apache Web Server.

Nginx status:

Root@server1 [~] # 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 17:18:29 server1.centos7-test.com systemd [1]: Starting nginx-nDeploy-high performance web server...Jan 17 17:18:29 server1.centos7-test .com nginx [3804]: nginx: the configuration file / etc/nginx/nginx.conf syntax is okJan 17 17:18:29 server1.centos7-test.com nginx [3804]: nginx: configuration file / etc/nginx/nginx.conf test is successfulJan 17 17:18:29 server1.centos7-test.com systemd [1]: Started nginx-nDeploy-high performance web server.

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

Root@server1 [/ usr/local/src] # netstat-plan | grep httpdtcp 0 0 0 plan 4430 0 0 0 plan * LISTEN 17270/httpdtcp 0 0 0 9 99 0 0 0 plan * LISTEN 17270/httpdtcp6 0 0:: 4430:: * LISTEN 17270/httpdtcp6 0 0: 9999: * LISTEN 17270/httpdroot@server1 [/ usr/local/src] # netstat-plan | grep nginxtcp 0 0 127.0.0.1 : 80 0.0.0.0 LISTEN 17802/nginx * LISTEN 17802/nginx: mastertcp 0 045.79 183.73 3 LISTEN 17802/nginx: master

The configuration file for virtual hosts created for existing users is in "/ etc/nginx/sites-enabled". This file path contains the main Nginx configuration files.

Root@server1 [/ etc/nginx/sites-enabled] # ll | grep .conf-rw-r--r-- 1 root root 311 Jan 17 09:02 saheetha.com.conf-rw-r--r-- 1 root root 336 Jan 17 09:02 saheethastest.com.conf

Example virtual host for a domain name:

Server {listen 45.79.183.73 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 launch a browser to view the website to determine the working status of the Web server. After installation, read the web service information on the server.

Root@server1 [/ home] # ip a | grep-I eth03: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000inet 45.79.183.73 qdisc pfifo_fast state UP qlen 1000inet 24 brd 45.79.183.255 scope global dynamic eth0root@server1 [/ home] # nginx-vnginx version: nginx/1.8.0

Nginx will create a virtual host for any newly created account in cPanel. With these simple steps, we can configure Nginx as a reverse proxy on a CentOS 7 / cPanel server.

Advantages of Nginx as a reverse proxy

Easy to install and configure. High efficiency and good performance. Prevent Ddos attacks. Support the use of. Htaccess as the rewriting rule for PHP. After reading this, the article "how to configure Nginx reverse proxy with cPanel in CentOS 7" has been introduced. If you want to master the knowledge of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report