打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Nginx配置(yum)

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

  

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
CentOS 7配置LNMP开发环境及配置文件管理
ubuntu 18.04 安装 LNMP
Lniux下搭建LNMP环境
阿里云腾讯云服务器手动配置WordPress网站教程
CentOS 7下安装LNMP服务器 – 戊辰人博客
RHEL / CentOS 7 安裝 Nginx, MySQL, PHP (LEMP) | Linux 技術手札
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服