* 假设 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. (一)Linux之目录结构

    Linux之目录结构 目录 Linux之目录结构 一.概述 一.基本介绍 二.具体的目录结构(不用背,知道即可) Linux /usr目录 Linux /var 目录 一.概述 学习 Linux,不仅 ...

  2. oracle给system用户增加sysdba和sysoper 角色

    第一步:先用sys用户登录到数据库 第二步:打开一个sql窗口,输入grant sysoper to system;  点击执行 第三步:等待执行完成之后,再执行grant sysdba to sys ...

  3. MySQL临时表与内存表

    在MySQL中有三种虚拟表:临时表.内存表.视图.下面简单介绍一下临时表和内存表的使用. 1.临时表 MySQL临时表在我们需要保存一些临时数据时是非常有用的.临时表在MySQL 3.23版本中添加. ...

  4. MySql 改变table的列名以及列的类型

    1 ALTER TABLE table_name CHANGE COLUMN old_col_name new_col_name datatype; #改变table的列名以及列的类型

  5. Dynamics CRM实体系列之1:N、N:1以及N:N关系

    Dynamics CRM在实施过程中会遇到很多多个实体关联的问题,这样可以实现多个实体的记录通过关联的字段实现数据的综合展示,在Sql Server里面叫做外键,在Dynamics CRM叫做关系.D ...

  6. ros-kinetic install error: sudo rosdep init ImportError: No module named 'rosdep2'

    refer to: https://blog.csdn.net/yueyueniaolzp/article/details/85070093 方法一 将Ubuntu默认python版本设置为2.7 方 ...

  7. 运行uni-app到微信开发者工具

    1.工具及环境 HBuilder X 微信开发者工具 Node.js,测试:node -v(node安装) 和 npm -v(自带的npm也安装成功) 2.创建uni-app项目: 在点击工具栏里的文 ...

  8. 老司机带你体验SYS库多种新玩法

    导读 如何更加愉快地利用sys库做一些监控? 快来,跟上老司机,体验sys库的多种新玩法~ MySQL5.7的新特性中,非常突出的特性之一就是sys库,不仅可以通过sys库完成MySQL信息的收集,还 ...

  9. 编写你的第一个Django应用

    安装 Python 作为一个 Python Web 框架,Django 需要 Python.更多细节请参见 我应该使用哪个版本的 Python 来配合 Django?. Python 包含了一个名为  ...

  10. Spring源码浅析之bean实例的创建过程(二)

    在上一篇内容中,介绍了doGetBean方法的源码内容,知道了bean在创建的过程中,有三个范围,单例.多例.Scope,里面都使用到了createBean.下面本篇文章的主要内容,就是围绕creat ...