安装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是自己在配置文件中定义的;

 

posted @ 2018-11-20 13:36  米兰的小铁將  阅读(2111)  评论(0编辑  收藏  举报