Nginx系列-8.配置Nginx+Apache實現動靜分離
阿新 • • 發佈:2018-06-10
Linux Nginx Apache 動靜分離 Nginx系列-8.配置Nginx+Apache實現動靜分離
目錄 - Nginx系列
Nginx系列-1.Linux下安裝Nginx
Nginx系列-2.配置LNMP(Linux、Nginx、MySQL、PHP)架構
Nginx系列-3.配置Nginx虛擬主機
Nginx系列-4.Nginx日誌配置及日誌切割
Nginx系列-5.配置Nginx的防盜鏈
Nginx系列-6.配置Nginx的HTTPS
Nginx系列-7.配置Nginx使用uwsgi支持web.py框架
Nginx系列-8.配置Nginx+Apache實現動靜分離
Nginx系列-9.配置NFS實現Nginx實現動靜分離Nginx系列-10.采用Nginx搭建正向代理服務
Nginx系列-11.配置Nginx反向代理和負載均衡
實驗環境
兩臺最小化的 CentOS 7.3 虛擬機
server1-ip: 192.168.204.133
server2-ip: 192.168.204.134
實驗拓撲
一、server1 安裝配置 Nginx
-
安裝
nginx
yum install -y epel-* yum install -y nginx vim
-
建立
nginx
主目錄和主頁mkdir /var/wwwroot cd /var/wwwroot echo -e "nginx" >> nginx.html
-
配置
nginx
配置文件vim /etc/nginx/nginx.conf
將默認server
塊修改如下server { listen 80; server_name _; location / { root /var/wwwroot; index index.html index.htm; } location ~ \.php$ { proxy_pass http://[apache‘s ip address]; #修改為Apache的IP地址 proxy_set_header host $host; } }
-
重啟
nginx
服務systemctl restart nginx
- 關閉防火墻
setenforce 0 systemctl stop firewalld systemctl disable firewalld
二、server2 安裝配置 Apache 和 PHP
-
安裝
Apache
和PHP
yum install -y httpd php
-
在
Apache
的Web根目錄(/var/www/html
)建立PHP文件cd /var/www/html echo -e "<?php phpinfo(); ?>" >> info.php
-
重啟
Apache
服務systemctl restart httpd
- 關閉防火墻
setenforce 0 systemctl stop firewalld systemctl disable firewalld
三、測試動靜分離,宿主機訪問server1
-
訪問
http://192.168.204.133/nginx.html
返回的是server1
上的資源
- 訪問PHP頁面
http://192.168.204.133/info.php
返回的是server2
上的資源
Nginx系列-8.配置Nginx+Apache實現動靜分離