主机 | IP |
---|---|
DR | 192.168.30.244/24 |
RS1(动态网页) | 192.168.30.245/24 |
RS2(静态网页) | 192.168.30.246/24 |
配置动态网页
[root@RS1 ~]# cd /usr/local/nginx/html/
[root@RS1 html]# vim index.php
<html>
<head>
<title>PHP 测试</title>
</head>
<body>
<p>danamic</p>
</body>
</html>
[root@RS1 ~]# vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html;
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
[root@RS1 ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:9000 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 80 :::3306 :::*
————————————————————————————————————————————————————
配置静态网页
[root@RS2 ~]# echo 'static' > /var/www/html/index.html
[root@RS2 ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
————————————————————————————————————————————————————
配置动静分离
[root@DR ~]# vim /usr/local/nginx/conf/nginx.conf
upstream static { ##静态
server 192.168.30.245:80 weight=1;
}
upstream danamic { ##动态
server 192.168.30.246:80 weight=1;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://static; ##反向代理
}
location ~ \.php$ { ## ~ \.(php|jsp)$有多种格式
proxy_pass http://danamic; ##反向代理
}
[root@DR ~]# nginx -s reload
http://192.168.30.244/index.html
————————————————————————————————————————
http://192.168.30.244/index.php