美文网首页
nginx单端口多服务

nginx单端口多服务

作者: SodaCrush | 来源:发表于2024-08-29 17:31 被阅读0次

    nginx配置

    /etc/nginx/nginx.conf

    # For more information on configuration, see:
    #   * Official English Documentation: http://nginx.org/en/docs/
    #   * Official Russian Documentation: http://nginx.org/ru/docs/
    
    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    
    # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
            log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                              '$status $body_bytes_sent "$http_referer" '
                              '"$http_user_agent" "$http_x_forwarded_for"';
    
            access_log  /var/log/nginx/access.log  main;
    
            sendfile            on;
            tcp_nopush          on;
            tcp_nodelay         on;
            keepalive_timeout   65;
            types_hash_max_size 4096;
    
            include             /etc/nginx/mime.types;
            default_type        application/octet-stream;
    
            # Load modular configuration files from the /etc/nginx/conf.d directory.
            # See http://nginx.org/en/docs/ngx_core_module.html#include
            # for more information.
            include /etc/nginx/conf.d/*.conf;
    
            # crawlab service
            upstream craw {
                    server localhost:6080;
            }
    
            # other service, e.g. Flask
            upstream file {
                    server localhost:7080;
            }
    
    
            server {
                    listen       8088;
                    listen       [::]:8088;
                    server_name  localhost;
                    #root         /usr/share/nginx/html;
    
                    # Load configuration files for the default server block.
                    include /etc/nginx/default.d/*.conf;
    
    
                    location /js {
                            # 将/js/xxx.js 重定向到 /crawlab/js/xxx.js
                            rewrite ^/js/(.*)$ /crawlab/js/$1 last;
                            proxy_pass http://craw/;
                            
                    }
                    location /assets {
                            rewrite ^/assets/(.*)$ /crawlab/assets/$1 last;
                            proxy_pass http://craw/;
                    }
                    location /simplemde {
                            rewrite ^/simplemde/(.*)$ /crawlab/simplemde/$1 last;
                            proxy_pass http://craw/;
                    }
                    location /api {
                            rewrite ^/api/(.*)$ /crawlab/api/$1 last;
                            proxy_pass http://craw/;
                    }
    
                    location /crawlab {
                            proxy_pass http://craw/;
                            rewrite ^/crawlab/(.*)$ /$1 break;
                    }
    
                    #location /crawlab/api {
                    #        proxy_pass http://craw/;
                    #        rewrite ^/crawlab/api/(.*)$ /$1 break;
                    #}
    
                    location /file {
                            # 去除请求路径中的 /file 前缀,并将请求发送到指定服务
                            rewrite ^/file/(.*)$ /$1 break;
                            proxy_pass http://file/;
                    }
            }
    }
    

    相关文章

      网友评论

          本文标题:nginx单端口多服务

          本文链接:https://www.haomeiwen.com/subject/levxljtx.html