zoukankan      html  css  js  c++  java
  • koa2 nginx 服务器配置

    需要实现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)
    
    
    需要注意的是,由于路径问题,前缀需要处理,不然会一直提示NOT FOUND
  • 相关阅读:
    实现RHEL下KVM虚拟化
    SELinux安全扩展
    配置用户和组信息
    系统级计划任务
    syslog系统日志服务
    VNC远程连接,虚拟网络计算
    系统初始化
    备份与还原文件系统
    使用对象在方法间共享属性
    Python中*和**的使用
  • 原文地址:https://www.cnblogs.com/mapleChain/p/14325917.html
Copyright © 2011-2022 走看看