Nginx配置(yum)
一:
# setenforce 0 # systemctl stop firewalld //尽量使用国内源 # yum install -y epel-release # cd /etc/yum.repos.d/ # yum install -y nginx # killall httpd //有Apache服务先关 # systemctl restart nginx # ps aux | grep nginx
或
二:nginx源下载
# cd /etc/yum.repos.d/ # rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm # vim nginx.repo # yum -y install nginx # systemctl restart nginx
Nginx配置支持PHP
-
在/etc/nginx/conf.d/目录下存放着多个配置文件,这些配置文件在Nginx运行时加载到主配置项目中(类似虚拟机)
-
Nginx是通过php-fpm来通讯的,所以需要监听9000端口
-
在这个目录下生成一个自己的配置文件例如admin.conf
# vim /etc/nginx/conf.d/admin.conf
server {
listen 80;
server_name www.test.com admin.test.com;
index index.html inex.htm index.php;
root /var/www/card/public;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
# yum install -y php-fpm
# vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
# cd /var/www
# mkdir -p card/public
# cd card/public
# vim php_info.php
<?php
echo "php解析正常"
?>
# systemctl restart php-fpm
# lsof -i:9000
# systemctl restart nginx
# setenforce 0
# systemctl stop firewalld
//192.168.1.2/php_info.php
Nginx配置反向代理
192.168.1.3 web端
192.168.1.2 代理服务器(www.test.com)
# cd /etc/nginx/conf.d/
# mv admin.conf admin.conf.bak
# rm -rf default.conf.rpmsave
# vim default.conf
upstream test{
server 192.168.1.3 weight=1 #权重越高访问次数越多
}
server {
listen 80;
server_name www.test.com;
access_log /var/log/nginx/host.access.log main;
location / {
proxy_pass http://test; #这里可直接写IP地址进行配置,如果需要配置负载均衡,可以使用http://test和upstream名称一致
}
}
# systemctl restart nginx
#
//web端
# systemctl stop firewalld
# setenforce 0
配置若有遗漏或错误,请评论留言。

浙公网安备 33010602011771号