php nginx 路径批量配置
* 假设 E:\upload 作为图片上传的位置 nginx 做web服务
* 创建文件conf.php 放到这个目录下
<?php
function handleDir($it, &$a) {
foreach ($it as $fileinfo) {
if ($fileinfo->isDir()) {
$filename = $it->getFilename();
if ($filename !== "." && $filename !== "..") {
array_push($a, $filename);
}
}
}
} $it = new \DirectoryIterator("."); $baseDir = preg_replace('/\\\\/', '/', __DIR__); $filenames = [];
handleDir($it, $filenames); $out = new SplFileObject($baseDir."/out.txt", "w+"); array_walk($filenames, function($value, $key, $dir) use ($out) {
$path = $dir .'/'.$value;
$out->fwrite("location /".$value." {".PHP_EOL);
$out->fwrite(" alias ".$path.";".PHP_EOL);
$out->fwrite(" allow all;".PHP_EOL);
$out->fwrite(" autoindex on;".PHP_EOL);
$out->fwrite(" charset utf-8,gbk;".PHP_EOL);
$out->fwrite("}".PHP_EOL);
}, $baseDir); /*
location /schoolhomepage {
alias E:/upload/schoolhomepage;
allow all;
autoindex on;
charset utf-8,gbk;
}
*/
* 把out.txt粘贴到 nginx 的conf路径下的nginx.conf文件中的对应位置
#user nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 8089;
server_name localhost;
#charset koi8-r;
charset utf-8;
#access_log logs/host.access.log main; location / {
root html;
index index.html index.htm;
charset utf-8;
} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /appPoster {
alias E:/upload/appPoster;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /images {
alias E:/upload/images;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /include {
alias E:/upload/include;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /png {
alias E:/upload/png;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /poster {
alias E:/upload/poster;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /publish {
alias E:/upload/publish;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /reporterActivity {
alias E:/upload/reporterActivity;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /schoolhomepage {
alias E:/upload/schoolhomepage;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /userAvatar {
alias E:/upload/userAvatar;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /webPoster {
alias E:/upload/webPoster;
allow all;
autoindex on;
charset utf-8,gbk;
}
location /writerActivity {
alias E:/upload/writerActivity;
allow all;
autoindex on;
charset utf-8,gbk;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # 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;
# include fastcgi_params;
#} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#} }
nginx.conf
* 重启nginx服务

php nginx 路径批量配置的更多相关文章
- Nginx 安装及配置、负载均衡https网站及转发后页面js、css等路径找不到问题、更换证书导致问题解决
官网下载nginx:http://nginx.org/en/download.html 安装nginx编译环境:yum install -y gcc-c++ 安装pcre库解析正则:yum insta ...
- Nginx服务安装配置
1.Nginx介绍 Nginx是一个高性能的HTTP和反向代理服务器,由俄罗斯人开发的,第一个版本发布于2004年10月4日.Nginx由于出色的性能,在世界范围内受到了越来越多人的关注,其特点是占有 ...
- Nginx的安装配置
1.安装PCRE库 $ cd /usr/local/ $ https://sourceforge.net/projects/pcre/files/pcre/8.36/ $ tar -zxvf pcre ...
- nginx入门篇----nginx服务器基础配置
1.nginx.conf文件结构... #全局块 events{ ... } http #http块{ ...
- nginx反向代理配置及优化
nginx反向代理配置及优化前言: 由于服务器apache抗不住目前的并发.加上前端squid配置后,问题依然无法解决.而页面程序大部分是动态.无法使用fastcgi来处理.因此想使用nginx做为反 ...
- LVS + Keepalived + Nginx安装及配置
1.概述 上篇文章<架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/artic ...
- windows下nginx+php简单配置
Nginx+php运行环境搭建 虽然目前nginx使用很广泛,在大陆主流的互联网站点或多或少会用到这个俄国人开发的小应用(占用资源小).但是我这个土鳖还是第一次自己独立配置,网上资料不少,但是还是遇到 ...
- nginx 的基础配置[转]
nginx 的基础配置 分类: 工具软件2013-11-13 23:26 11人阅读 评论(0) 收藏 举报 目录(?)[-] 管理配置文件 全局配置 虚拟机server配置 location配置 ...
- 利用nginx泛域名解析配置二级域名和多域名
利用nginx泛域名解析配置二级域名和多域名 网站的目录结构为 html ├── bbs └── www html为nginx的安装目录下默认的存放源代码的路径. bbs为论坛程序源代码路径 www为 ...
随机推荐
- 图文详解两种算法:深度优先遍历(DFS)和广度优先遍历(BFS)
参考网址:图文详解两种算法:深度优先遍历(DFS)和广度优先遍历(BFS) - 51CTO.COM 深度优先遍历(Depth First Search, 简称 DFS) 与广度优先遍历(Breath ...
- springboot中添加事务注解
1.首先在service层中的方法前添加@Transactional @Service public class UserService { @Autowired private UserMapper ...
- MVVMLight学习笔记(三)---数据双向绑定
一.概述 本文与其说是MVVMLight框架的学习,不如说是温故一下数据的双向绑定. 二.Demo 建立好MVVMLight框架后的Wpf工程后,建立一个Model.Model.View以及ViewM ...
- POI实现excel的导入导出
引入依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</arti ...
- [ASP.NET MVC]@Html.ActionLik重载
一 Html.ActionLink("linkText","actionName") 该重载的第一个参数是该链接要显示的文字,第二个参数是对应的控制器的方法, ...
- Linux下用gdb 调试、查看代码堆栈
Linux中用gdb 查看代码堆栈的信息 core dump 一般是在segmentation fault(段错误)的情况下产生的文件,需要通过ulimit来设置才会得到的. 调试的话输入: gd ...
- JDBC基础篇(MYSQL)——通过JDBC连接数据库的三种方式
package day01_jdbc; import java.sql.Connection; import java.sql.Driver; import java.sql.DriverManage ...
- 单例模式-案例Runtime
package d.create_type_single; import java.io.IOException; /** * Runtime类就是使用的单例:并且是饿汉式 * (原因考虑是因为:多线 ...
- Servlet的特点及运行过程
- shiro登录源码
//1.获取SecurityManager工厂,此处使用Ini配置文件初始化SecurityManager Factory<org.apache.shiro.mgt.SecurityManage ...