准备一个nginx代理 两个http 分别处理动态和静态。
1.配置nginx反向代理upstream;
vim /etc/nginx/ngnx.conf
upstream static {
server 10.0.105.196:80 weight=1 ;
}
upstream php {
server 10.0.105.200:80 weight=1 ;
}
server {
listen 80;
server_name localhost;
#动态资源加载
location ~ .(php|jsp)$ {
proxy_pass http://php; #要和上面创建的 php 一致
}
#静态资源加载
location ~ .*.(html|gif|jpg|png|bmp|swf|css|js)$ {
proxy_pass http://static; #要和上面创建的 static 一致
}
}
静态资源配置
vim /etc/nginx/ngnx.conf
server {
listen 80;
server_name localhost;
location ~ .(html|jpg|png|js|css|gif|bmp|jpeg) {
root /home/www/nginx;
}
}
动态资源配置:
yum 安装php7.1
[root@nginx-server ~]#rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
[root@nginx-server ~]#rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@nginx-server ~]#yum install php71w-xsl php71w php71w-ldap php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath php71w-mcrypt -y
[root@nginx-server ~]#yum install -y php71w-fpm
[root@nginx-server ~]#systemctl start php-fpm
[root@nginx-server ~]#systemctl enable php-fpm
编辑nginx的配置文件:
vim /etc/nginx/ngnx.conf
server {
listen 80;
server_name localhost;
location ~ .php$ {
root /home/nginx/html; #指定网站目录
fastcgi_pass 127.0.0.1:9000; #指定访问地址
fastcgi_index index.php; #指定默认文件
fastcgi_param SCRIPT_FILENAME
d
o
c
u
m
e
n
t
r
o
o
t
document_root
documentrootfastcgi_script_name; #站点根目录,取决于root配置项
include fastcgi_params; #包含nginx常量定义
}
}
**#要在网站发布目录里创建一个“index.php"的文件
#vim /home/nginx/html/index.php 把下面内容添加进去
<?php
phpinfo();
?>
php index.php 执行一下
访问动态网页是时ip加上动态页面文件
如 10.11.56.67:/index.php