mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-03 23:40:14 +08:00
PUB:20160218 How to Set Nginx as Reverse Proxy on Centos7 CPanel
@bestony
This commit is contained in:
parent
0d970e9361
commit
68c204c2e5
@ -1,16 +1,15 @@
|
|||||||
|
如何在 CentOS 7 用 cPanel 配置 Nginx 反向代理
|
||||||
如何在 CentOS 7 cPanel 上 配置 Nginx 作为反向代理
|
|
||||||
================================================================================
|
================================================================================
|
||||||
|
|
||||||
Nginx 是最快和最强大的 Web-Server 之一。以其高性能和低资源利用率而闻名。它可以被安装为一个独立的Web服务器和反向代理Web服务器。在这篇文章,我将讨论在安装了 cPanel 服务器的 Centos 7 服务器上安装Nginx作为Apache的反向代理服务器.
|
Nginx 是最快和最强大的 Web 服务器之一,以其高性能和低资源占用率而闻名。它既可以被安装为一个独立的 Web 服务器,也可以安装成反向代理 Web 服务器。在这篇文章,我将讨论在安装了 cPanel 管理系统的 Centos 7 服务器上安装 Nginx 作为 Apache 的反向代理服务器。
|
||||||
|
|
||||||
Nginx 作为反向代理为静态文件提供服务,Apache 作为后端为动态文件提供服务。这个设置将整体提高服务器的性能。
|
Nginx 作为前端服务器用反向代理为静态文件提供服务,Apache 作为后端为动态文件提供服务。这个设置将整体提高服务器的性能。
|
||||||
|
|
||||||
让我们过一遍在已经安装好 cPanel 11.52 的 CentOS 7 x86_64 服务器上配置 Nginx 作为反向代理的安装过程。
|
让我们过一遍在已经安装好 cPanel 11.52 的 CentOS 7 x86_64 服务器上配置 Nginx 作为反向代理的安装过程。
|
||||||
|
|
||||||
首先,我们需要安装 EPEL 库来启动这个进程
|
首先,我们需要安装 EPEL 库来启动这个进程
|
||||||
|
|
||||||
### 第一步: 安装EPEL库. ###
|
### 第一步: 安装 EPEL 库###
|
||||||
|
|
||||||
root@server1 [/usr]# yum -y install epel-release
|
root@server1 [/usr]# yum -y install epel-release
|
||||||
Loaded plugins: fastestmirror, tsflags, universal-hooks
|
Loaded plugins: fastestmirror, tsflags, universal-hooks
|
||||||
@ -26,13 +25,13 @@ Nginx 作为反向代理为静态文件提供服务,Apache 作为后端为动
|
|||||||
|
|
||||||
Dependencies Resolved
|
Dependencies Resolved
|
||||||
|
|
||||||
===============================================================================================================================================
|
========================================================================================
|
||||||
Package Arch Version Repository Size
|
Package Arch Version Repository Size
|
||||||
===============================================================================================================================================
|
========================================================================================
|
||||||
Installing:
|
Installing:
|
||||||
epel-release noarch 7-5 extras 14 k
|
epel-release noarch 7-5 extras 14 k
|
||||||
|
|
||||||
### 第二步: 安装完成这个 Repo ,我们可以安装 nDeploy的 CentOS RPM 库来安装我们需要的 nDeploy Webstack 和 Nginx 插件. ###
|
### 第二步: 可以安装 nDeploy 的 CentOS RPM 库来安装我们所需的 nDeploy Web 类软件和 Nginx 插件 ###
|
||||||
|
|
||||||
root@server1 [/usr]# yum -y install http://rpm.piserve.com/nDeploy-release-centos-1.0-1.noarch.rpm
|
root@server1 [/usr]# yum -y install http://rpm.piserve.com/nDeploy-release-centos-1.0-1.noarch.rpm
|
||||||
Loaded plugins: fastestmirror, tsflags, universal-hooks
|
Loaded plugins: fastestmirror, tsflags, universal-hooks
|
||||||
@ -46,13 +45,13 @@ Nginx 作为反向代理为静态文件提供服务,Apache 作为后端为动
|
|||||||
|
|
||||||
Dependencies Resolved
|
Dependencies Resolved
|
||||||
|
|
||||||
===============================================================================================================================================
|
========================================================================================
|
||||||
Package Arch Version Repository Size
|
Package Arch Version Repository Size
|
||||||
===============================================================================================================================================
|
========================================================================================
|
||||||
Installing:
|
Installing:
|
||||||
nDeploy-release-centos noarch 1.0-1 /nDeploy-release-centos-1.0-1.noarch 110
|
nDeploy-release-centos noarch 1.0-1 /nDeploy-release-centos-1.0-1.noarch 110
|
||||||
|
|
||||||
### 第三步:安装 nDeploy 和 Nginx nDeploy 插件. ###
|
### 第三步:安装 nDeploy 和 Nginx nDeploy 插件 ###
|
||||||
|
|
||||||
root@server1 [/usr]# yum --enablerepo=ndeploy install nginx-nDeploy nDeploy
|
root@server1 [/usr]# yum --enablerepo=ndeploy install nginx-nDeploy nDeploy
|
||||||
Loaded plugins: fastestmirror, tsflags, universal-hooks
|
Loaded plugins: fastestmirror, tsflags, universal-hooks
|
||||||
@ -65,9 +64,9 @@ Nginx 作为反向代理为静态文件提供服务,Apache 作为后端为动
|
|||||||
|
|
||||||
Dependencies Resolved
|
Dependencies Resolved
|
||||||
|
|
||||||
===============================================================================================================================================
|
========================================================================================
|
||||||
Package Arch Version Repository Size
|
Package Arch Version Repository Size
|
||||||
===============================================================================================================================================
|
========================================================================================
|
||||||
Installing:
|
Installing:
|
||||||
nDeploy noarch 2.0-11.el7 ndeploy 80 k
|
nDeploy noarch 2.0-11.el7 ndeploy 80 k
|
||||||
nginx-nDeploy x86_64 1.8.0-34.el7 ndeploy 36 M
|
nginx-nDeploy x86_64 1.8.0-34.el7 ndeploy 36 M
|
||||||
@ -79,12 +78,12 @@ Nginx 作为反向代理为静态文件提供服务,Apache 作为后端为动
|
|||||||
python-lxml x86_64 3.2.1-4.el7 base 758 k
|
python-lxml x86_64 3.2.1-4.el7 base 758 k
|
||||||
|
|
||||||
Transaction Summary
|
Transaction Summary
|
||||||
===============================================================================================================================================
|
========================================================================================
|
||||||
Install 2 Packages (+5 Dependent packages)
|
Install 2 Packages (+5 Dependent packages)
|
||||||
|
|
||||||
有以上这些步骤,我们完成了在我们的服务器上 Nginx 插件的安装。现在我们可以配置 Nginx 作为反向代理和为已有的 cPanel 用户账户创建虚拟主机,为此我们可以运行如下脚本。
|
通过以上这些步骤,我们完成了在我们的服务器上 Nginx 插件的安装。现在我们可以配置 Nginx 作为反向代理和为已有的 cPanel 用户账户创建虚拟主机,为此我们可以运行如下脚本。
|
||||||
|
|
||||||
### 第四步:启动Nginx作为默认的前端 Web 服务器 并创建默认的配置文件。 ###
|
### 第四步:启动 Nginx 作为默认的前端 Web 服务器,并创建默认的配置文件###
|
||||||
|
|
||||||
root@server1 [/usr]# /opt/nDeploy/scripts/cpanel-nDeploy-setup.sh enable
|
root@server1 [/usr]# /opt/nDeploy/scripts/cpanel-nDeploy-setup.sh enable
|
||||||
Modifying apache http and https port in cpanel
|
Modifying apache http and https port in cpanel
|
||||||
@ -96,9 +95,9 @@ Nginx 作为反向代理为静态文件提供服务,Apache 作为后端为动
|
|||||||
ConfGen:: saheetha
|
ConfGen:: saheetha
|
||||||
ConfGen:: satest
|
ConfGen:: satest
|
||||||
|
|
||||||
你可以看到这个脚本将修改 Apache 的端口从 80 到另一个端口来让 Nginx 作为前端 Web 服务器并为现有的 cPanel 用户创建虚拟主机配置文件。一旦完成,确认 Apache 和 Nginx 的状态。
|
你可以看到这个脚本将修改 Apache 的端口从 80 到另一个端口来让 Nginx 作为前端 Web 服务器,并为现有的 cPanel 用户创建虚拟主机配置文件。一旦完成,确认 Apache 和 Nginx 的状态。
|
||||||
|
|
||||||
### Apache 状态: ###
|
#### Apache 状态:####
|
||||||
|
|
||||||
root@server1 [/var/run/httpd]# systemctl status httpd
|
root@server1 [/var/run/httpd]# systemctl status httpd
|
||||||
● httpd.service - Apache Web Server
|
● httpd.service - Apache Web Server
|
||||||
@ -113,7 +112,7 @@ Nginx 作为反向代理为静态文件提供服务,Apache 作为后端为动
|
|||||||
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 apachectl[25606]: httpd (pid 24760) already running
|
||||||
Jan 18 06:34:23 server1.centos7-test.com systemd[1]: Started Apache Web Server.
|
Jan 18 06:34:23 server1.centos7-test.com systemd[1]: Started Apache Web Server.
|
||||||
|
|
||||||
### Nginx 状态: ###
|
#### Nginx 状态:####
|
||||||
|
|
||||||
root@server1 [~]# systemctl status nginx
|
root@server1 [~]# systemctl status nginx
|
||||||
● nginx.service - nginx-nDeploy - high performance web server
|
● nginx.service - nginx-nDeploy - high performance web server
|
||||||
@ -132,7 +131,7 @@ Nginx 作为反向代理为静态文件提供服务,Apache 作为后端为动
|
|||||||
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 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.
|
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。请看他们的情况
|
Nginx 作为前端服务器运行在 80 端口,Apache 配置被更改为监听 http 端口 9999 和 https 端口 4430。请看他们的情况:
|
||||||
|
|
||||||
root@server1 [/usr/local/src]# netstat -plan | grep httpd
|
root@server1 [/usr/local/src]# netstat -plan | grep httpd
|
||||||
tcp 0 0 0.0.0.0:4430 0.0.0.0:* LISTEN 17270/httpd
|
tcp 0 0 0.0.0.0:4430 0.0.0.0:* LISTEN 17270/httpd
|
||||||
@ -146,13 +145,13 @@ Nginx 作为前端服务器运行在 80 端口,Apache 配置被更改为监听
|
|||||||
tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 17802/nginx: master
|
tcp 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
|
tcp 0 0 45.79.183.73:80 0.0.0.0:* LISTEN 17802/nginx: master
|
||||||
|
|
||||||
为已有用户创建的虚拟主机的配置文件在 "**/etc/nginx/sites-enabled**". 这个文件路径包含了 Nginx 主要配置文件.
|
为已有用户创建的虚拟主机的配置文件在 "**/etc/nginx/sites-enabled**"。 这个文件路径包含了 Nginx 主要配置文件。
|
||||||
|
|
||||||
root@server1 [/etc/nginx/sites-enabled]# ll | grep .conf
|
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 311 Jan 17 09:02 saheetha.com.conf
|
||||||
-rw-r--r-- 1 root root 336 Jan 17 09:02 saheethastest.com.conf
|
-rw-r--r-- 1 root root 336 Jan 17 09:02 saheethastest.com.conf
|
||||||
|
|
||||||
### 一个域名的示例虚拟主机: ###
|
#### 一个域名的示例虚拟主机:###
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
|
||||||
@ -168,7 +167,7 @@ Nginx 作为前端服务器运行在 80 端口,Apache 配置被更改为监听
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
我们可以启动浏览器查看完整来确定 Web 服务器的工作状态。安装后,请阅读服务器上的 web 服务信息。
|
我们可以启动浏览器查看网站来确定 Web 服务器的工作状态。安装后,请阅读服务器上的 web 服务信息。
|
||||||
|
|
||||||
root@server1 [/home]# ip a | grep -i eth0
|
root@server1 [/home]# ip a | grep -i eth0
|
||||||
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
|
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
|
||||||
@ -178,16 +177,16 @@ Nginx 作为前端服务器运行在 80 端口,Apache 配置被更改为监听
|
|||||||
|
|
||||||
![webserver-status](http://blog.linoxide.com/wp-content/uploads/2016/01/webserver.png)
|
![webserver-status](http://blog.linoxide.com/wp-content/uploads/2016/01/webserver.png)
|
||||||
|
|
||||||
|
Nginx 将会为任何最新在 cPanel 中创建的账户创建虚拟主机。通过这些简单的的步骤,我们能够在一台 CentOS 7 / cPanel 的服务器上配置 Nginx 作为反向代理。
|
||||||
|
|
||||||
Nginx 将会为任何最新在 cPanel 中创建的账户创建虚拟主机。通过这些简单的的步骤,我们能够在一台 CentOS 7 / cPanel 的服务器上配置 Nginx 作为反向代理
|
### Nginx 作为反向代理的优势###
|
||||||
### Nginx 作为反向代理的优势 : ###
|
|
||||||
|
|
||||||
1. 便于安装和配置
|
1. 便于安装和配置。
|
||||||
2. 效率高性能好
|
2. 效率高、性能好。
|
||||||
3. 防止 Ddos 攻击
|
3. 防止 Ddos 攻击。
|
||||||
4. 支持使用.htaccess作为PHP的重写规则
|
4. 支持使用 .htaccess 作为 PHP 的重写规则。
|
||||||
|
|
||||||
我希望这篇文章对你们有用。感谢你提到它。我非常高兴收到你的宝贵意见和建议,并进一步改善。
|
我希望这篇文章对你们有用。感谢你看它。我非常高兴收到你的宝贵意见和建议,并进一步改善。
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -195,7 +194,7 @@ via: http://linoxide.com/linux-how-to/set-nginx-reverse-proxy-centos-7-cpanel/
|
|||||||
|
|
||||||
作者:[Saheetha Shameer][a]
|
作者:[Saheetha Shameer][a]
|
||||||
译者:[bestony](https://github.com/bestony)
|
译者:[bestony](https://github.com/bestony)
|
||||||
校对:[校对者ID](https://github.com/校对者ID)
|
校对:[wxy](https://github.com/wxy)
|
||||||
|
|
||||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||||
|
|
Loading…
Reference in New Issue
Block a user