nginx的模块和状态和安装php

Nginx模块

目录索引模块

http_autoindex_module

http_index_module

location / {
  autoindex on;
}

 

显示大小,带单位

Syntax: autoindex_exact_size on | off;
Default:
autoindex_exact_size on;
Context: http, server, location

显示北京时间

Syntax: autoindex_localtime on | off;
Default:
autoindex_localtime off;
Context: http, server, location

 

 

状态模块

location = /basic_status {
  stub_status;
}
This configuration creates a simple web page with basic status data which may look like as follows:

Active connections: 291
server accepts handled requests
16630948 16630948 31070465
Reading: 6 Writing: 179 Waiting: 106

 

 

访问控制

#限制IP
  location /status {
        stub_status;
        allow 172.16.1.0/24;
        deny all;
  }
 


location /status {
      stub_status;
      allow all;
      deny $IP;
}

 

#限制用户密码
location / {
  auth_basic           "closed site";
  auth_basic_user_file conf/htpasswd;
}

server {
      listen 80;
      server_name www.simi.xxx;

      location / {
              root /simi;
              index simi.html;
              auth_basic           "simi";
              auth_basic_user_file /simi/simi.passwd;
      }

}

 

 

访问限制

1)连接限制

http {
  limit_conn_zone $remote_addr zone=suibian:10m;
}

 

2)限制请求数量

http {
  limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

server {
  location /search/ {
      limit_req zone=one burst=5 nodelay;
      limit_req_status 412;
      error_page 412 /xxx/err.html
  }
}

location

匹配符匹配规则优先级
= 精确匹配 1
^~ 以某个字符串开头 2
~ 区分大小写的正则匹配 3
~* 不区分大小写的正则匹配 3
!~ 区分大小写不匹配的正则 5
!~* 不区分大小写不匹配的正则 6
/ 通用匹配,任何请求都会匹配到  
server 
server_name www.driverzeng.com;

location / {
  root /code
}

location ~ .php$ {
  root /var/www
}

location ~ .jsp$ {
  ...
}

location ~* .(jpg|gif|png|js|css)$ {
  root /req;
}

location ~* .(sql|bak|tgz|tar.gz|.git)$ {
  ...
}

www.driverzeng.com/index.PHP
www.driverzeng.com/abc.tgz
www.driverzeng.com/ABC.tgz
www.driverzeng.com/ABC.jsp
www.driverzeng.com/ABC.JSP
www.driverzeng.com/abc.JSP

LNMP环境准备

1)使用nginx官方源


[root@web01 ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@web01 ~]# cd /etc/yum.repos.d/
[root@web01 yum.repos.d]# vim nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

2)创建nginx用户

[root@web01 ~]# groupadd www -g 666
[root@web01 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M

3)安装nginx

[root@web01 ~]# yum install -y nginx

4)修改nginx启动用户

[root@web01 ~]# vim /etc/nginx/nginx.conf 
user www;

5)启动nginx加入开机自启

[root@web01 ~]# systemctl start nginx
[root@web01 ~]# systemctl enable nginx

 

安装php

#卸载系统自带的php5.4
[root@web01 ~]# yum remove php-mysql-5.4 php php-fpm php-commo
#配置第三方源
[root@nginx ~]# vim /etc/yum.repos.d/php.repo
[php-webtatic]
name = PHP Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0

#更改php源
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
#安装php

[root@nginx ~]# yum -y install php71-php php71-php-cli php71-php-common php71-php-devel php71-php-embedded php71-php-gd php71-php-mcrypt php71-php-mbstring php71-php-pdo php71-php-xml php71-php-fpm php71-php-mysqlnd php71-php-opcache php71-php-pecl-memcached php71-php-pecl-redis php71-php-pecl-mongodb
[root@web01 yum.repos.d]# cd /etc/opt/remi/php71/

[root@web01 php71]# ll
total 76
drwxr-xr-x 2 root root     6 Feb 20 19:46 opt
drwxr-xr-x 2 root root 4096 Aug 16 15:58 php.d
-rw-r--r-- 1 root root 4103 Jul 31 16:37 php-fpm.conf
drwxr-xr-x 2 root root   22 Aug 16 15:58 php-fpm.d
-rw-r--r-- 1 root root 62394 Jul 31 16:37 php.ini
drwxr-xr-x 2 root root     6 Feb 20 19:46 pki
drwxr-xr-x 5 root root   52 Aug 16 15:57 pm
drwxr-xr-x 2 root root     6 Feb 20 19:46 skel
drwxr-xr-x 2 root root   21 Aug 16 15:58 sysconfig
drwxr-xr-x 4 root root   38 Aug 16 15:57 X11
drwxr-xr-x 3 root root   23 Aug 16 15:57 xdg
drwxr-xr-x 2 root root     6 Feb 20 19:46 xinetd.d
[root@web01 php71]# cd php-fpm.d
[root@web01 php-fpm.d]# ll
total 20
-rw-r--r-- 1 root root 19478 Jul 31 16:37 www.conf

 

寻找启动命令
[root@web01 php-fpm.d]# rpm -qa|grep php
[root@web01 php-fpm.d]# rpm -ql php71-php-fpm-7.1.31-1.el7.remi.x86_64
[root@web01 php-fpm.d]# /opt/remi/php71/root/usr/sbin/php-fpm   启动php
[root@web01 php-fpm.d]# ps -ef|grep php     查看是否启动php
root       7838     1 0 16:08 ?       00:00:00 php-fpm: master process (/etc/opt/remi/php71/php-fpm.conf)
www       7839   7838 0 16:08 ?       00:00:00 php-fpm: pool www
www       7840   7838 0 16:08 ?       00:00:00 php-fpm: pool www
www       7841   7838 0 16:08 ?       00:00:00 php-fpm: pool www
www       7842   7838 0 16:08 ?       00:00:00 php-fpm: pool www
www       7843   7838 0 16:08 ?       00:00:00 php-fpm: pool www
root       7845   7472 0 16:10 pts/1   00:00:00 grep --color=auto php
root@web01 ~]# cd /etc/nginx/conf.d/
[root@web01 conf.d]# ll
total 4
-rw-r--r-- 1 root root 1093 Aug 13 23:02 default.conf

[root@web01 conf.d]# vim php.conf

server {
      listen 80;
      server_name php.oldboy.com;
      root /code;
      index index.php index.html index.htm;


      location ~ .php$ {
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      include       fastcgi_params;
}
  }
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@web01 conf.d]# nginx -s reload
[root@web01 conf.d]# mkdir /code
[root@web01 conf.d]# ll
total 8
-rw-r--r-- 1 root root 1093 Aug 13 23:02 default.conf
-rw-r--r-- 1 root root 314 Aug 16 16:45 php.conf
[root@web01 conf.d]# cd /code/
[root@web01 code]# ll
total 0
[root@web01 code]# vim index.php


<?php
phpinfo();
?>
[root@web01 code]# chown -R www.www /code

[root@web01 code]# nginx -t
[root@web01 code]# nginx -s reload
访问 php.oldboy.com就会出现php的界面 前提是要先做域名解析

[root@web01 code]# vim index.php
<font color='pink'> 小仙女</font>
<?php
phpinfo();
?>
然后刷新一下就会出现 php的界面上出现小仙女的字
 

[root@web01 conf.d]# vim req.conf

server {
      listen 80;
      server_name req.drz.com;
      limit_req zone=xxx burst=3 nodelay;
      location /{
      root /req;
      index index.html;
}
}

1)安装httpd和php

[root@web01 ~]# yum install -y httpd php

2)创建用户

[root@web01 ~]# groupadd www -g 666
[root@web01 ~]# useradd www -u 666 -g 666 -s /sbin/nologin -M

3)修改配置文件

[root@web01 ~]# vim /etc/httpd/conf/httpd.conf
User www
Group www
[root@web01 conf.d]# mkdir /req
[root@web01 ~]# cd /etc/nginx/conf.d/
[root@web01 conf.d]# chown -R www.www /req
[root@web01 req]# vim index.html
<font color='pink'> i am gril</font>

[root@web01 req]# vim /etc/nginx/conf.d/req.conf 
limit_req_zone $remote_addr zone=mingzi:10m rate=1r/s;

server {
      listen 80;
      server_name game.abc.com;
      limit_req zone=mingzi burst=1 nodelay;
      limit_req_status 412;

      location / {
      root /req;
      index index.html;
}
}

 server {
      listen 80;
      server_name dir.abc.com;
      charset utf-8,gbk;
      autoindex on;
      location /{
              root /dir;
        autoindex_exact_size off;
        autoindex_localtime on;
      auth_basic     "abc";
      auth_basic_user_file /code/aa;

}
      location /download {
      alias /dir;
      autoindex on;
}
      location /status {
      stub_status;
}

}

 

原文地址:https://www.cnblogs.com/223zhp/p/11370487.html