* 假设 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 路径批量配置的更多相关文章

  1. Nginx 安装及配置、负载均衡https网站及转发后页面js、css等路径找不到问题、更换证书导致问题解决

    官网下载nginx:http://nginx.org/en/download.html 安装nginx编译环境:yum install -y gcc-c++ 安装pcre库解析正则:yum insta ...

  2. Nginx服务安装配置

    1.Nginx介绍 Nginx是一个高性能的HTTP和反向代理服务器,由俄罗斯人开发的,第一个版本发布于2004年10月4日.Nginx由于出色的性能,在世界范围内受到了越来越多人的关注,其特点是占有 ...

  3. Nginx的安装配置

    1.安装PCRE库 $ cd /usr/local/ $ https://sourceforge.net/projects/pcre/files/pcre/8.36/ $ tar -zxvf pcre ...

  4. nginx入门篇----nginx服务器基础配置

    1.nginx.conf文件结构...                         #全局块  events{  ...  }  http                      #http块{ ...

  5. nginx反向代理配置及优化

    nginx反向代理配置及优化前言: 由于服务器apache抗不住目前的并发.加上前端squid配置后,问题依然无法解决.而页面程序大部分是动态.无法使用fastcgi来处理.因此想使用nginx做为反 ...

  6. LVS + Keepalived + Nginx安装及配置

    1.概述 上篇文章<架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/artic ...

  7. windows下nginx+php简单配置

    Nginx+php运行环境搭建 虽然目前nginx使用很广泛,在大陆主流的互联网站点或多或少会用到这个俄国人开发的小应用(占用资源小).但是我这个土鳖还是第一次自己独立配置,网上资料不少,但是还是遇到 ...

  8. nginx 的基础配置[转]

    nginx 的基础配置 分类: 工具软件2013-11-13 23:26 11人阅读 评论(0) 收藏 举报   目录(?)[-] 管理配置文件 全局配置 虚拟机server配置 location配置 ...

  9. 利用nginx泛域名解析配置二级域名和多域名

    利用nginx泛域名解析配置二级域名和多域名 网站的目录结构为 html ├── bbs └── www html为nginx的安装目录下默认的存放源代码的路径. bbs为论坛程序源代码路径 www为 ...

随机推荐

  1. Centos7-编译安装zlib

    1.解压并进入zlib目录tar xf zlib-1.2.11.tar.gz cd zlib-1.2.11 2.查看编辑参数[root@manage zlib-1.2.11]#./configure ...

  2. 【翻译稿】Behavior Driven Development (BDD)行为驱动开发

    这是一篇翻译稿,方便给不知道BDD的同学扫盲.原文链接:What is BDD (Behavior Driven Development)? | Agile Alliance Definition定义 ...

  3. CGO入门和OCR文字识别(非第三方API,有源码,效果好)实战

    这是我参与8月更文挑战的第5天,活动详情查看:8月更文挑战 系列文章见: [第四天] GDB调试指南:C++中如何调试生产环境的程序? [第三天] IM敏感词算法原理和实现 [第二天] 现代IM架构研 ...

  4. 【阿菜Writeup】Security Innovation Smart Contract CTF

    赛题地址:https://blockchain-ctf.securityinnovation.com/#/dashboard Donation 源码解析 我们只需要用外部账户调用 withdrawDo ...

  5. [SWMM]弗汝德数

    弗汝德数(Froude number)是流体内惯性力与重力的比值.弗汝德数(Fr)是水力学中重要的无量纲数之一,它表示过水断面上单位重量液体具有的平均动能与平均势能的比值,它也表示水流惯性力与重力的比 ...

  6. 三 MongoDB进阶

    1 Limit方法 概念:查询指定数量的数据,该方法接受一个数字参数作为查询记录数的数量 举个例子:查询集合col中最多2条记录数 2 Skip方法 概念:查询到的结果集中,跳过指定数量的数据,该方法 ...

  7. 在ubuntu18.04上部署项目时遇到的问题总结

    因为在实验室中,有几台空闲的机子,我便选了一台准备做一个本地的服务器,因为买的阿里云学生机和之前用于FQ的机子感觉都不太顺手,阿里的学生机配置稍低,FQ用的服务器延迟太高.开始在centos和ubun ...

  8. Spring第一课:核心API(三)

    以上是Spring的核心部分,其中需要了解的是:BeanFactory.ApplicationContext[FileSystemXmlApplicationContext.ClassPathXmlA ...

  9. kettle 查询 tinyint 值为 Y,kettle 查询 tinyint 为布尔值

     问题解决方法 1.在数据库连接中的[选项]命令参数中加入:tinyInt1isBit = false,如下图: 实际场景:

  10. Python代码阅读(第2篇):数字转化成列表

    本篇阅读的代码实现了将输入的数字转化成一个列表,输入数字中的每一位按照从左到右的顺序成为列表中的一项. 本篇阅读的代码片段来自于30-seconds-of-python. digitize def d ...