nginx实验笔记

版权声明:请尊重每个人的努力! https://blog.csdn.net/IndexMan/article/details/88895697

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|cur|gz|svg|svgz|mp4|ogg|ogv|webm)$

{

         expires      360d;

}

 

location ~ .*\.(?:js|css)$

{

         expires      360d;

}

 

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.配置负载均衡

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

猜你喜欢

转载自blog.csdn.net/IndexMan/article/details/88895697