* 假设 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. Adaptive AUTOSAR 学习笔记 15 - 持久化 Persistency

    本系列学习笔记基于 AUTOSAR Adaptive Platform 官方文档 R20-11 版本 AUTOSAR_EXP_PlatformDesign.pdf.作者:Zijian/TENG 原文地 ...

  2. [1.6W字]浏览器跨域请求的原理, 以及解决方法(可以纯前端实现) #flight.Archives011

    Title/ 浏览器跨域(CrossOrigin)请求的原理, 以及解决方案详细指南 #flight.Archives011 序: 最近看到又有一波新的创作活动了, 官方给出的话题中有一个" ...

  3. metasploit的数据库配置

    metasploit所处位置:/usr/share/metasploit-framework msf数据库连接命令:db_connect msf:msfadmin@127.0.0.1/msf 1.启动 ...

  4. spring boot 整合JPA bean注入失败

    有时候报的错误让你匪夷所思,找错误得学会找根.源头在哪里? 比如:我们刚开始看的错误就是 org.springframework.beans.factory.UnsatisfiedDependency ...

  5. .net core 通过动软连接数据库

    .net core 与动软 首先创建asp.net core 或者 .net core 控制台程序.不需急着创建web.config 文件. 通过NuGet加个ado的包 System.Data.Sq ...

  6. JdbcTemplateUtils

    package com.meeno.common.utils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.J ...

  7. npm 基本命令的使用

    1.npm -v 查看npm版本 2.使用npm命令安装模块 npm install Module Name 例如安装jquery模块 npm install jquery 3.卸载模块 npm un ...

  8. npm常用命令及其node相关工具汇总

    它是一个事件驱动异步I/O单进程的服务端JS环境,基于Google的V8引擎,V8引擎执行Javascript的速度非常快,性能非常好. 浏览器是JS的前端运行环境. Node.js是JS的后端运行环 ...

  9. 3、二进制安装K8s之部署kube-apiserver

    二进制安装K8s之部署kube-apiserver 一.生成 kube-apiserver 证书 1.自签证书颁发机构(CA) cat > ca-config.json <<EOF ...

  10. 配置之XML--读取XML文件 转存为Key-Value

    将XML文件读取 绑定数据至Dictionary Eg: Xml文件 <?xml version="1.0" encoding="utf-8" ?> ...