需要实现nginx访问文件和代理node服务端口
--- 配置
server {
listen 80 default_server;
# server_name _;
root /test;
# roor : 设置静态资源访问路径
# Load configuration files for the default server block.
#include /etc/nginx/default.d/*.conf;
location / {
# 开启各种文件下载
autoindex on;
if ($request_filename ~* ^.*?.(png|exe|pdf|jpg|avi)$) {
add_header Content-Disposition attachment;
add_header Content-Type application/octet-stream;
}
}
location /app {
# 你的服务和端口
proxy_pass http://127.0.0.1:2333;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
--- nodejs服务路由配置
import Router from "koa-router"
...
urlPrefix: {
prefix: "/app", // 前缀需要和nginx代理配置一样
},
const router: any = new Router(config?.urlPrefix)