編碼的世界 / 優質文選 / 財富

解決nginx在windows環境下location中root路徑空格問題


2022年5月22日
-   

nginx在Windows環境下location中root路徑有空格問題解決方案:

#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 8090;
server_name localhost;
root D://workspaces//test//member.website//src//main//webapp;
access_log logs/access.log;
error_log logs/error.log;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
error_page 404 /404.html;
location ~ /opleo {
proxy_pass http://leo.op.com;
}
location ~ .(ipa|apk|bmp|css|doc|docx|et|exe|gif|htm|html|ico|jpg|js|pdf|png|rar|swf|txt|xls|xlsx|xsl|zip|eot|svg|ttf|woff|log|json|php)$
{
expires 20s;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:7001;
#proxy_pass http://backed;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
server {
listen 8990;
server_name localhost;
location = / {
root "D:/Program Files (x86)/cdn";
}
}
}

如上代碼的nginx配置中,8990端口下對應的所有請求都代理到D:Program Files (x86)cdn這個目錄,而路徑中包含空格,只要把整個路徑用雙引號引起來就OK,博主已經親自試過了,弄了好久才解決整個問題………… linux下針對這種路徑,好像只要在空格前面加上””反斜杠轉義下就行(但是沒親測)

熱門文章