目录
一、windows10 系统配置nginx文件服务器
1、到nginx官网上下载windows版本的nginx,地址http://nginx.org/en/download.html
2、把下载的包放在电脑磁盘里解压,注意解压的包的路径不能包含中文字符,否则nginx服务启动不了
3、启动nginx服务
3.1、用windows键+R键打开“运行”,输入“cmd”进行,进入“D:\nginx-server\nginx-1.14.2”目录下
3.2、在任务管理器查看是否成功启动了,查看到下面的两个nginx才确保nginx服务启动成功了
4、修改配置,重启nginx服务
4.1、主要添加内容为
4.2、重新加载nginx服务
5、用127.0.0.1:8099访问下载
6、windows版本的nginx相关命令
二、CentOS 7系统配置nginx文件服务器
1、先装好nginx
2、修改nginx.conf配置文件
3、设置nginx的文件管理器的目录
在日常工作中,用nginx作文件管理器比python3 -m http.server创建的文件服务器稳定,所以nginx用作文件管理器也挺受欢迎的,稳定也快!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
一、windows10 系统配置nginx文件服务器
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1、到nginx官网上下载windows版本的nginx,地址http://nginx.org/en/download.html
++++++++++++++++++++++
2、把下载的包放在电脑磁盘里解压,注意解压的包的路径不能包含中文字符,否则nginx服务启动不了
3、启动nginx服务
3.1、用windows键+R键打开“运行”,输入“cmd”进行,进入“D:\nginx-server\nginx-1.14.2”目录下
C:\Users\li>d:
D:\>cd nginx-1.14.2
D:\nginx-1.14.2>start nginx.exe #启动命令
D:\nginx-1.14.2>
3.2、在任务管理器查看是否成功启动了,查看到下面的两个nginx才确保nginx服务启动成功了
4、修改配置,重启nginx服务
#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;
}
# 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;
# }
#}
#添加文件管理器
autoindex on;# 显示目录
autoindex_exact_size on;# 显示文件大小
autoindex_localtime on;# 显示文件时间
server {
listen 8099;
server_name localhost ;
root D:\install ;#本地文件路径
}
# 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;
# }
#}
}
4.1、主要添加内容为
#添加文件管理器
autoindex on;# 显示目录
autoindex_exact_size on;# 显示文件大小
autoindex_localtime on;# 显示文件时间
server {
listen 8099;
server_name localhost ;
root D:\install ;#本地文件路径 #同时注意不能直接以整个逻辑磁盘D:\ 为目录路径,要d:\英文文件名
}
#把你要下载的多个文件目录打包为压缩包(如zip包),方便下载
4.2、重新加载nginx服务
D:\nginx-1.14.2>nginx.exe -s reload #重新加载nginx命令
D:\nginx-1.14.2>
5、用127.0.0.1:8099访问下载
注意:文件名要为英文字符的才正常下载,带有中文字符的文件点击下载时,会报错500
5.1、要文件名为英名字符的才正常下载,如下
6、windows版本的nginx相关命令
nginx -s stop //停止nginx
nginx -s reload //重新加载nginx
nginx -s quit //退出nginx
start nginx //启动nginx
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
二、CentOS 7系统配置nginx文件服务器
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
1、先装好nginx
(注意:nginx服务和配置的文件都是用nginx用户及nginx组授权的)
2、修改nginx.conf配置文件
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 65535;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
# autoindex off;
client_max_body_size 1000m; #主要是这个参数,限制了上传文件大大小
server_names_hash_max_size 512;
server_names_hash_bucket_size 512;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
server {
listen 1666;
server_name localhost;
root /nginx/install ;
}
}
3、设置nginx的文件管理器的目录
[root@docker-test ~]# mkdir /nginx/install
[root@docker-test ~]# mkdir /nginx/install
[root@docker-test ~]# chmod -R nginx:nginx /nginx/install
[root@docker-test ~]# /usr/local/nginx/sbin/nginx -s reload