PHP nginx Path Batch Configuration

Source: Internet
Author: User

* Assuming E:\upload as the image upload location nginx do Web services

* Create file conf.php in this directory

<?phpfunction Handledir ($it, & $a) {foreach ($it as $fileinfo) {if ($fileinfo->isdir ()) {$filename = $it->get Filename (); 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;} */

  

* Paste the OUT.txt to the corresponding location in the nginx.conf file under the Nginx conf path

#user nobody;worker_processes1; #error_log logs/Error.log, #error_log logs/error.log notice; #error_log logs/error.logInfo; #pid logs/nginx.pid;events {worker_connections1024x768;}    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_timeout0; Keepalive_timeout $; #gzipOn ; server {Listen8089;        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_page404/404. html; # REDIRECT Server error pages to the static page/50x.html # Error_page - 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 on127.0.0.1: the# #location~\.php$ {# Proxy_pass http://127.0.0.1;#} # Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000# #location~\.php$ {# root HTML; # Fastcgi_pass127.0.0.1:9000;        # Fastcgi_index index.php; # Fastcgi_param Script_filename/Scripts$fastcgi_script_name;        # include Fastcgi_params; #} # Deny access to. htaccess files,ifApache'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 {# listen8000; # Listen Somename:8080;    # server_name somename alias Another.alias; # Location/{# root HTML;    # index index.html index.htm; #} #} # HTTPS Server # #server {# listen443SSL;    # 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

* Restart Nginx Service

PHP nginx Path Batch Configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.