nginx实战笔记

1.添加一个虚拟机

/usr/local/nginx/sbin

./nginx -t

nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

 

[root@localhost sbin]# netstat -nltp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      23976/nginx: master

tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN      23976/nginx: master

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      975/sshd           

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      2071/master        

tcp6       0      0 :::22                   :::*                    LISTEN      975/sshd           

tcp6       0      0 ::1:25                  :::*                    LISTEN      2071/master

 

访问:http://192.168.43.139:81/

 

server {
        listen          81;
        server_name     localhost;
        access_log      logs/test.log;
        location / {
            index index.html;
            root  html/test;
        }
    }


 

cd /usr/local/nginx/html/

mkdir test
cd test
vim index.html

cd /usr/local/nginx/sbin/

[root@localhost sbin]# ls

nginx

[root@localhost sbin]# ./nginx -s reload

 

 

2.centos7安装php7

https://www.yiibai.com/nginx/nginx-php7-source-config.html

cd /opt

wget -c http://cn2.php.net/distributions/php-7.1.3.tar.gz

 

##安装依赖

yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel

yum install -y wget gcc gcc-c++ autoconf libjpeg libjpeg-devel perl perl* perl-CPAN libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers png jpeg autoconf gcc cmake make gcc-c++ gcc ladp ldap* ncurses ncurses-devel zlib zlib-devel zlib-static pcre pcre-devel pcre-static openssl openssl-devel perl libtoolt openldap-devel libxml2-devel ntpdate cmake gd* gd2 ImageMagick-devel jpeg jpeg* pcre-dev* fontconfig libpng libxml2 zip unzip gzip

cp /usr/local/src/php-7.1.3/php.ini-production /usr/local/php7/etc/php.ini

 

3.nginx代理php

修改配置文件:

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {
         root           html;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include        fastcgi_params;
}

 

 

4.配置静态缓存

location ~ .*\.(?:jpg|jpeg|gif|png|ico|gz|svg|svgz|mp4)$
{
   expires   30d;
}
 
location ~ .*\.(?:js|css)$
{
   expires   10d;
}
 
location ~ .*\.(?:htm|html)$
{
  add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate";
}

 

 

 

 

 

5.开启gzip压缩

gzip on;
gzip_min_length  1k;
gzip_buffers     4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/x-httpd-php image/jpeg image/gif image/png;
gzip_vary on;
gzip_proxied   expired no-cache no-store private auth;
gzip_disable   "MSIE [1-6]\.";

 

6.配置负载均衡

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值