安裝Nginx作為文件服務器


我是在Windows上安裝的,在Linux上也一樣

#Windows server2008 R2

#Nginx1.12

 

Nginx安裝包下載地址:http://nginx.org/en/download.html

 

一、安裝、啟動Nginx

1、下載進行解壓,將解壓后的文件放到某目錄下;

2、進入window的cmd窗口,進入到nginx目錄,使用“start nginx.exe ”啟動Nginx;

3、啟動成功后,在“任務管理器”中會看到“nginx.exe”進程;

4、在瀏覽器地址欄輸入:127.0.0.1 會看到nginx的歡迎界面;

  相關命令:   

    start nginx.exe     //啟動
    nginx.exe -s stop      //停止nginx
    nginx.exe -s reload   //重新加載nginx
    nginx.exe -s quit     //退出nginx

以上步驟很簡單;

二、配置為文件服務器

1、配置文件服務器,其實主要是改配置文件就行了;

  如果Nginx在啟動狀態,先停止;

2、下面l貼出整個配置文件內容:

#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 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
      root html;
      index index.html index.htm;
    }

    #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 /data {
      alias E:\data;         #共享目錄
      allow all;           #都允許
      autoindex_exact_size on;     # 顯示文件大小
      autoindex_localtime on;     # 顯示文件時間
      autoindex on;        # 顯示目錄
    }

    # 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;
    # }

  #}

}

 

3、改完配置文件,啟動nginx, 用瀏覽器訪問  http://ip/data    即可,此處ip為Nginx服務器的ip,/data是自己在配置文件中定義的;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM