Niginx 配置前端代理服务器和常见问题

一、 nginx配置步骤

  1. 首先在官网http://nginx.org/en/download.html下载nginx,下载它的稳定版本
  1. 然后在nginx-1.16.1conf下修改配置文件nginx.conf

配置代理如下

server {

listen 8089;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

proxy_intercept_errors on;

recursive_error_pages on;

root "D:workCode\resources"; //项目目录

# ~* .(html|js|css|png|jpg)$

location / {

index index_dev.htm; //首页文件

proxy_pass http://10.118.65.168:8082;

}

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

server {

listen 8089;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

proxy_intercept_errors on;

recursive_error_pages on;

root "E:workvrVRfrontdist";

# ~* .(html|js|css|png|jpg)$

location / {

index index.html;

}

proxy_pass http://10.11.150.73:57682;

proxy_set_header Host $host;

#proxy_redirect off;

#proxy_set_header X-Forwarded-For #$proxy_add_x_forwarded_for;

}

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

}

二、启动脚本

每次都去点击niginx.exe的启动和关闭也很麻烦,可以写一个简单的启动脚本.bat来启动nginx

@echo kill the ngix

taskkill /pid nginx.exe /f

@echo start the ngix

d:

cd/work/nginx-1.16.1

start nginx.exe

@echo start the ngix successful!

Pause

    常见问题
  1. 在写目录的时候一定要注意是不含有n,t,r这些键盘字符,存在的即用//代替/
经验分享 程序员 微信小程序 职场和发展