一、修改配置文件(nginx.conf)
nginx-1.21.6\conf\nginx.conf
http {
···
#文件夹目录显示
autoindex on; #开启目录浏览功能;
autoindex_exact_size off; #关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;
autoindex_localtime on; #开启以服务器本地时区显示文件修改日期!
charset utf-8; #在中文路径会出现问题(还需要配置window的编码)
···
server {
···
location /porject {
root F:/Desktop; #自己的文件位置
#访问
#http://127.0.0.1/porject 会出现文件夹目录
#访问地址(例子)
#(http://127.0.0.1/porject/HTML/test.html)== (F:\Desktop\porject\HTML\test.html)
index index.html index.htm;
}
···
二、访问中文路径
注意:配置好后访问中文路径可能会出现(文件名乱码,error, not found)的问题
原因:此问题是由于windows系统编码与nginx编码设置不一致导致的,因此我们要统一二者的编码(2个都要)
1、nginx编码
http {
···
charset utf-8; #在中文路径会出现问题(还需要配置window的编码)
···
server {
···
2、windows编码设置
区域设置=>其他日期、时间和区域设置=>区域=>管理=>更改系统区域设置=>选上Bate版DBeta 版:使用 Unicode UTF-8 提供全球语言支持(U)=>重启即可

其他日期、时间和区域设置

区域

管理

更改系统区域设置

选上Bate版DBeta 版:使用 Unicode UTF-8 提供全球语言支持(U)

重启

三、全部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;
#文件夹目录显示
autoindex on; #开启目录浏览功能;
autoindex_exact_size off; #关闭详细文件大小统计,让文件大小显示MB,GB单位,默认为b;
autoindex_localtime on; #开启以服务器本地时区显示文件修改日期!
charset utf-8;
#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 http://192.168.10.55;
#charset koi8-r;
#access_log logs/host.access.log main;
location /porject {
root F:/Desktop;
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;
# }
#}
# 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;
# }
#}
}