Nginx配置(yum),第1張

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 /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=/ 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.3web耑

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

  

 


生活常識_百科知識_各類知識大全»Nginx配置(yum)

0條評論

    發表評論

    提供最優質的資源集郃

    立即查看了解詳情