目錄
第二步: 安裝nDeploy 的CentOS RPM 庫
可以安裝nDeploy 的CentOS RPM 庫來安裝我們所需的nDeploy Web 類別軟體和Nginx 外掛程式
首頁 運維 Nginx CentOS 7中怎麼使用cPanel來設定Nginx反向代理

CentOS 7中怎麼使用cPanel來設定Nginx反向代理

May 21, 2023 pm 05:43 PM
centos nginx cpanel

cPanel是目前世界上功能最強大,最容易使用,最受使用者歡迎的虛擬主機控制系統,許多國外主機主機都使用這套控制面板。

CentOS 7中怎么使用cPanel配置Nginx反向代理

首先,我們需要安裝EPEL 函式庫來啟動這個程序

第一步: 安裝EPEL 函式庫

root@server1 [/usr]# yum -y install epel-releaseLoaded plugins: fastestmirror, tsflags, universal-hooks
Loading mirror speeds from cached hostfile
* EA4: 66.23.237.210
* base: mirrors.linode.com
* extras: mirrors.linode.com
* updates: mirrors.linode.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-5 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
   Package Arch Version Repository Size
========================================================================================
Installing:
epel-release noarch 7-5 extras 14 k
登入後複製

第二步: 安裝nDeploy 的CentOS RPM 庫

可以安裝nDeploy 的CentOS RPM 庫來安裝我們所需的nDeploy Web 類別軟體和Nginx 外掛程式

root@server1 [/usr]# yum -y install http://rpm.piserve.com/nDeploy-release-centos-1.0-1.noarch.rpmLoaded plugins: fastestmirror, tsflags, universal-hooks
nDeploy-release-centos-1.0-1.noarch.rpm | 1.7 kB 00:00:00
Examining /var/tmp/yum-root-ei5tWJ/nDeploy-release-centos-1.0-1.noarch.rpm: nDeploy-release-centos-1.0-1.noarch
Marking /var/tmp/yum-root-ei5tWJ/nDeploy-release-centos-1.0-1.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package nDeploy-release-centos.noarch 0:1.0-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
nDeploy-release-centos noarch 1.0-1 /nDeploy-release-centos-1.0-1.noarch 110
登入後複製

第三步驟:安裝nDeploy 和Nginx nDeploy 插件

root@server1 [/usr]# yum --enablerepo=ndeploy install nginx-nDeploy nDeployLoaded plugins: fastestmirror, tsflags, universal-hooks
epel/x86_64/metalink | 9.9 kB 00:00:00
epel | 4.3 kB 00:00:00
ndeploy | 2.9 kB 00:00:00
(1/4): ndeploy/7/x86_64/primary_db | 14 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:02

Dependencies Resolved

========================================================================================
Package Arch Version Repository Size
========================================================================================
Installing:
nDeploy noarch 2.0-11.el7 ndeploy 80 k
nginx-nDeploy x86_64 1.8.0-34.el7 ndeploy 36 M
Installing for dependencies:
PyYAML x86_64 3.10-11.el7 base 153 k
libevent x86_64 2.0.21-4.el7 base 214 k
memcached x86_64 1.4.15-9.el7 base 84 k
python-inotify noarch 0.9.4-4.el7 base 49 k
python-lxml x86_64 3.2.1-4.el7 base 758 k

Transaction Summary
========================================================================================
Install 2 Packages (+5 Dependent packages)
登入後複製

我們在自己的伺服器上安裝了Nginx 插件,並按照上述步驟完成了安裝。現在我們可以設定 Nginx 作為反向代理和為現有的 cPanel 使用者帳戶建立虛擬主機,為此我們可以執行以下腳本。

第四步:啟動Nginx 作為預設的前端Web 伺服器,並建立預設的設定檔

root@server1 [/usr]# /opt/nDeploy/scripts/cpanel-nDeploy-setup.sh enableModifying apache http and https port in cpanel

httpd 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:: saheetha
ConfGen:: satest
登入後複製

你可以看到這個腳本將修改Apache 的連接埠從80 到另一個連接埠來讓Nginx 作為前端Web 伺服器,並為現有的cPanel 使用者建立虛擬主機設定檔。一旦完成,確認 Apache 和 Nginx 的狀態。

Apache 狀態:

root@server1 [/var/run/httpd]# systemctl status httpd● httpd.service - Apache Web Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-01-18 06:34:23 UTC; 12s ago
Process: 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 start

Jan 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 running
Jan 18 06:34:23 server1.centos7-test.com systemd[1]: Started Apache Web Server.
登入後複製

Nginx 狀態:

root@server1 [~]# systemctl status nginx● nginx.service - nginx-nDeploy - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2016-01-17 17:18:29 UTC; 13h ago
Docs: 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 process

Jan 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 ok
Jan 17 17:18:29 server1.centos7-test.com nginx[3804]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 17 17:18:29 server1.centos7-test.com systemd[1]: Started nginx-nDeploy - high performance web server.
登入後複製

Nginx 作為前端伺服器運行在80 端口,Apache 配置被更改為監聽http 連接埠9999 和https 連接埠4430。請看他們的情況:

root@server1 [/usr/local/src]# netstat -plan | grep httpdtcp 0 0 0.0.0.0:4430 0.0.0.0:* LISTEN 17270/httpd
tcp 0 0 0.0.0.0:9999 0.0.0.0:* LISTEN 17270/httpd
tcp6 0 0 :::4430 :::* LISTEN 17270/httpd
tcp6 0 0 :::9999 :::* LISTEN 17270/httpd
登入後複製
CentOS 7中怎么使用cPanel配置Nginx反向代理
root@server1 [/usr/local/src]# netstat -plan | grep nginxtcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 17802/nginx: master
tcp 0 0 45.79.183.73:80 0.0.0.0:* LISTEN 17802/nginx: master
登入後複製

為已有使用者建立的虛擬主機的設定檔在「/etc/nginx/sites-enabled」。這個檔案路徑包含了 Nginx 主要設定檔。

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
登入後複製

一個網域的範例虛擬主機:

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;

}
登入後複製

我們可以啟動瀏覽器檢視網站來決定 Web 伺服器的工作狀態。安裝後,請閱讀伺服器上的 web 服務資訊。

root@server1 [/home]# ip a | grep -i eth03: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
inet 45.79.183.73/24 brd 45.79.183.255 scope global dynamic eth0
root@server1 [/home]# nginx -vnginx version: nginx/1.8.0
登入後複製
CentOS 7中怎么使用cPanel配置Nginx反向代理

對該句話重寫,可得到:對於在 cPanel 中新建立的所有帳戶,Nginx 將會為它們建立虛擬主機。透過這些簡單的步驟,我們能夠在一台 CentOS 7 / cPanel 的伺服器上設定 Nginx 作為反向代理。

Nginx 作為反向代理的優勢

  1. #方便安裝與設定。

  2. 效率高、效能好。

  3. 防止 Ddos 攻擊。

  4. 支援使用 .htaccess 作為 PHP 的重寫規則。

以上是CentOS 7中怎麼使用cPanel來設定Nginx反向代理的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

怎樣優化CentOS HDFS配置 怎樣優化CentOS HDFS配置 Apr 14, 2025 pm 07:15 PM

提升CentOS上HDFS性能:全方位優化指南優化CentOS上的HDFS(Hadoop分佈式文件系統)需要綜合考慮硬件、系統配置和網絡設置等多個方面。本文提供一系列優化策略,助您提升HDFS性能。一、硬件升級與選型資源擴容:盡可能增加服務器的CPU、內存和存儲容量。高性能硬件:採用高性能網卡和交換機,提升網絡吞吐量。二、系統配置精調內核參數調整:修改/etc/sysctl.conf文件,優化TCP連接數、文件句柄數和內存管理等內核參數。例如,調整TCP連接狀態和緩衝區大小

docker容器名稱怎麼查 docker容器名稱怎麼查 Apr 15, 2025 pm 12:21 PM

可以通過以下步驟查詢 Docker 容器名稱:列出所有容器(docker ps)。篩選容器列表(使用 grep 命令)。獲取容器名稱(位於 "NAMES" 列中)。

centos關機命令行 centos關機命令行 Apr 14, 2025 pm 09:12 PM

CentOS 關機命令為 shutdown,語法為 shutdown [選項] 時間 [信息]。選項包括:-h 立即停止系統;-P 關機後關電源;-r 重新啟動;-t 等待時間。時間可指定為立即 (now)、分鐘數 ( minutes) 或特定時間 (hh:mm)。可添加信息在系統消息中顯示。

CentOS HDFS配置有哪些常見誤區 CentOS HDFS配置有哪些常見誤區 Apr 14, 2025 pm 07:12 PM

CentOS下Hadoop分佈式文件系統(HDFS)配置常見問題及解決方案在CentOS系統上搭建HadoopHDFS集群時,一些常見的錯誤配置可能導致性能下降、數據丟失甚至集群無法啟動。本文總結了這些常見問題及其解決方法,幫助您避免這些陷阱,確保HDFS集群的穩定性和高效運行。機架感知配置錯誤:問題:未正確配置機架感知信息,導致數據塊副本分佈不均,增加網絡負載。解決方案:仔細檢查hdfs-site.xml文件中的機架感知配置,並使用hdfsdfsadmin-printTopo

centos7如何安裝mysql centos7如何安裝mysql Apr 14, 2025 pm 08:30 PM

優雅安裝 MySQL 的關鍵在於添加 MySQL 官方倉庫。具體步驟如下:下載 MySQL 官方 GPG 密鑰,防止釣魚攻擊。添加 MySQL 倉庫文件:rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm更新 yum 倉庫緩存:yum update安裝 MySQL:yum install mysql-server啟動 MySQL 服務:systemctl start mysqld設置開機自啟動

Centos停止維護2024 Centos停止維護2024 Apr 14, 2025 pm 08:39 PM

CentOS將於2024年停止維護,原因是其上游發行版RHEL 8已停止維護。該停更將影響CentOS 8系統,使其無法繼續接收更新。用戶應規劃遷移,建議選項包括CentOS Stream、AlmaLinux和Rocky Linux,以保持系統安全和穩定。

docker怎麼創建容器 docker怎麼創建容器 Apr 15, 2025 pm 12:18 PM

在 Docker 中創建容器: 1. 拉取鏡像: docker pull [鏡像名] 2. 創建容器: docker run [選項] [鏡像名] [命令] 3. 啟動容器: docker start [容器名]

docker怎麼啟動容器 docker怎麼啟動容器 Apr 15, 2025 pm 12:27 PM

Docker 容器啟動步驟:拉取容器鏡像:運行 "docker pull [鏡像名稱]"。創建容器:使用 "docker create [選項] [鏡像名稱] [命令和參數]"。啟動容器:執行 "docker start [容器名稱或 ID]"。檢查容器狀態:通過 "docker ps" 驗證容器是否正在運行。

See all articles