赞
踩
作用: 匹配客户端响应
location [ = | ~ | ~* | ^~ ] uri { … }
优先级: =, ^~, ~, ~*, location /
location = /upload {
}
http://x.x.x.x/upload
location ~ /test {
}
http://x.x.x.x/upload/test
http://x.x.x.x/test/a/b/c
location ~ \.(jpg|jpeg|gif|png)$ {
}
location ~ \.php$ {
}
location ~* /download {
}
http://x.x.x.x/test/download/
http://x.x.x.x/DownLoad/test
location ^~ /test {
}
http://x.x.x.x/test
location /status {
stub_status;
access_log off;
allow 192.168.140.1;
deny all;
}
Active connections: 1 // 当前的活跃连接数
server accepts handled requests
2809 2809 2937
Reading: 0 Writing: 1 Waiting: 0
accepts:接收的连接数
handlerd:处理的连接
requests:请求数
让服务器接收到请求后,根据需求改写地址,以改写的地址给客户端响应
rewrite 旧uri地址 新uri地址;
注意:
1、旧uri匹配请求时,是不包含请求的参数,不包括?后面的内容
2、旧uri地址支持正则表达式
3、避免循环匹配,否则会产生5xx的错误
rewrite ^/audio/ http://music.linux.com/mp3/;
rewrite ^/audio/(.*) http://music.linux.com/mp3/$1;
rewrite ^/ https://www.jd.com;
if ($host = secure.linux.com) {
rewrite ^/(.*) https://secure.linux.com/$1;
}
将httpd换为nginx,高并发、高性能
nginx通过fastCGI机制调用PHP,处理动态资源
php以fpm的方式运行,有自己独立的进程、服务
[root@localhost ~]# yum install -y mariadb-server php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
[root@localhost ~]# systemctl enable --now mariadb
[root@localhost ~]# systemctl enable --now php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.
[root@localhost ~]#
[root@localhost ~]# netstat -tunlp | grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 7986/php-fpm: maste
[root@localhost conf.d]# vim vedio.conf
location ~ \.php$ {
root /vedio;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@localhost conf.d]# /usr/local/nginx/sbin/nginx -t
[root@localhost conf.d]# /usr/local/nginx/sbin/nginx -s reload
<?php
phpinfo();
?>
<?php
$link=mysqli_connect("localhost", "root", "");
if($link)
echo "ok";
else
echo "error";
?>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。