• 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服务

  • 相关阅读:
    一个特殊的SQL Server阻塞案例分析
    cannot be run because the QueueReader subsystem failed to load
    ORACLE中关于表的一些特殊查询语句
    ORACLE中如何查找定位表最后DML操作的时间小结
    MySQL慢查询日志释疑总结
    Windows服务器如何查看共享目录信息
    SQL Server Log Shipping学习总结
    连环清洁工之特殊任务--java资源如何关闭?
    花果山第一届猿类分级考试实录--Talk is cheap,Show me the code
    猿类如何捕获少女心--难以琢磨的try-catch
  • 原文地址:https://www.cnblogs.com/mingzhanghui/p/9367545.html
Copyright © 2020-2023  润新知