配置
-
进入nginx安装位置
-
进入conf文件夹,修改nginx.conf配置文件
cd conf vim nginx.conf
-
找到 server配置选项
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } # 其他地方都不重要,看这段代码 # 匹配所有以/api开头的请求 location /api { # 重写请求路径将/api去掉,例如/api/test改写成/test rewrite ^/api/(.*)$ /$1 break; # 代理到http://localhost:5000 proxy_pass http://localhost:5000; } # 以上代码会使得请求http://localhost:80/api/test # 转发到 http://localhost:5000/test #error_page 404 /404.html; # redirect server error pages to the static page