码迷,mamicode.com
首页 > Web开发 > 详细

php nginx 路径批量配置

时间:2018-07-25 19:02:03      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:rtu   上传   referer   ace   log   创建文件   director   ams   cal   

 * 假设 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 Apaches document root
        # concurs with nginxs 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 路径批量配置

标签:rtu   上传   referer   ace   log   创建文件   director   ams   cal   

原文地址:https://www.cnblogs.com/mingzhanghui/p/9367545.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!