nginx搭建文件服务器

nginx搭建文件服务器

安装:
sudo apt-get install nginx
启动:
nginx -c /etc/nginx/nginx.conf
或:
/etc/init.d/nginx start

创建server文件夹,将server.conf文件放在此文件夹中:
sudo mkdir/etc/nginx/server
server.conf文件(此文件中的/home/user/www是自定义的路径,并将需要访问的资源文件放在此文件夹中):
vim /etc/nginx/server/server.conf
加入:

server { 
        listen     81  ;
        server_name  localhost;


        location ~ \.(JPG|jpg|PNG|png|JPEG|jpeg|GIF|gif|BMP|bmp|MD|md|DOC|doc|DOCX|docx|PPT|ppt|PPTX|pptx|XLS|xls|XLSX|xlsx|PDF|pdf|RAR|rar|ZIP|zip|JAR|jar|TAR|tar|GZ|gz|mp4|MP4|txt|TXT)$ { 
                root /home/QiTech;    #需要手动去创建的文件夹
        }
   # location /{ 
#
 # root /home/user/www;
  # }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html { 
            root   html;
        }

}

进入到/etc/nginx/nginx.conf文件,将刚创建的server文件包含进来:
vim /etc/nginx/nginx.conf
配置
include /etc/nginx/server/;
此行配置需要放在http{}中:
http{
include /etc/nginx/server/

}

http { 

	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;

	##
	# Logging Settings
	##

	access_log /var/log/nginx/access.log;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;
	gzip_disable "msie6";

	# gzip_vary on;
	# gzip_proxied any;
	# gzip_comp_level 6;
	# gzip_buffers 16 8k;
	# gzip_http_version 1.1;
	# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

	##
	# Virtual Host Configs
	##

	#include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/server/*;
	include /etc/nginx/sites-enabled/*;
	#include /etc/nginx/sites-enabled/*;
}

然后检查nginx.conf是否有问题:
nginx -t -c /etc/nginx/nginx.conf
若没问题,会出现如下提示: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

重启nginx
/etc/init.d/nginx restart
然后访问 ip:8080+文件名称

    原文作者:Super令
    原文地址: https://blog.csdn.net/qq_41955670/article/details/120363137
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞