Windos Nginx开发准备

发布时间 2023-09-26 12:00:42作者: 1161588342

1. 下载 打开nginx.conf

    # Windows 修改第一处
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    
    # Windows 修改第二处, 新建conf.d文件夹,用来存配置文件
    include ../conf.d/*.conf;        

 

比如vue前端项目配置

server {
    listen       8020;
    server_name  localhost;
    
    # 静态文件地址
    root E:\xxx\folder;
    try_files $uri $uri/ /index.html;
    
    access_log logs/xxx-access.log main;
    error_log logs/xxx-error.log warn;

    location /status  {
        root html;
        stub_status on;
        access_log off;
    }
 
# 防止F5刷新404 location
/ { if (!-e $request_filename) { rewrite ^(.*)$ /index.html?s=$1 last; break; } error_page 500 502 503 504 = /50x.html; } location /stage-api/ { # 请求的后台地址 proxy_pass http://xxx.xxx.xxx.xxx:8080/; proxy_redirect off; #真实IP获取 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; set $my_proxy_add_x_forwarded_for $proxy_add_x_forwarded_for; if ($proxy_add_x_forwarded_for ~* "127.0.0.1"){ set $my_proxy_add_x_forwarded_for $remote_addr; } proxy_set_header X-Forwarded-For $my_proxy_add_x_forwarded_for; } }

 

> nginx.exe启动