nginx.conf相关配置记录

# 开启nginx并在后台运行
start nginx.exe

# 关闭nginx
nginx.exe -s stop

# 重载配置文件(不需要重启进程)
nginx.exe -s reload

# 查看nginx进程
tasklist /fi "imagename eq nginx.exe

#----------nginx---nginx.conf---相关配置记录-----------#
http {

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

sendfile off;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

  #上传文件大小10M
  client_max_body_size 10m;

#gzip on;

server {

listen 8082;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {

root html/zradmin/dist;
index index.html index.htm;
# 避免出现404
try_files $uri $uri/ /index.html;

       proxy_connect_timeout 180s; #连接超时 默认为60秒
       proxy_read_timeout 180s; #读取超时 默认为60秒
       proxy_send_timeout 180s; #发送超时 默认为60秒
       #proxy_buffer_size 68k;
       #proxy_buffers 4 68k;
       #proxy_busy_buffers_size 128k;
       #proxy_temp_file_write_size 128k;

proxy_set_header Host $host;
#给请求头中添加客户端IP
proxy_set_header X-Real-IP $remote_addr;
#将$remote_addr变量值添加在客户端“X-Forwarded-For”请求头的后面,并以逗号分隔。 如果客户端请求未携带“X-Forwarded-For”请求头,$proxy_add_x_forwarded_for变量值将与$remote_addr变量相同
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#给请求头中添加客户端的Cookie
proxy_set_header Cookie $http_cookie;
#将使用代理服务器的主域名和端口号来替换。如果端口是80,可以不加。
#proxy_redirect off;

add_header 'Access-Control-Allow-Origin' '*' ;
add_header 'Access-Control-Allow-Credentials' 'true' ;
add_header 'Access-Control-Allow-Methods' 'PUT,POST,GET,DELETE,OPTIONS' ;
add_header 'Access-Control-Allow-Headers' 'Content-Type,Content-Length,Authorization,Accept,X-Requested-With' ;

}

location /driver/img {
  proxy_pass http://localhost:78/img/;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /uploads {

# 设置资源存储路径地址
root G:\home\website;
# linux下对应 /home/website

autoindex on;

}

location /dev-api {

proxy_pass http://localhost:7777;
rewrite ^/dev-api/(.*)$ /$1 break;            #反向代理请求后台接口此处百度查找资料好多都没有这个介绍(重定向配置)没有此配置会404错误

}

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

root html;

}

}

}

posted @ 2022-09-16 15:53  Kiss丿残阳  阅读(42)  评论(0编辑  收藏  举报