配置springboot项目

#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    client_max_body_size 2048m;

    #gzip  on;

	upstream proxy_store {
       ip_hash;
       server 127.0.0.1:6789;     #业务逻辑后台系统地址
    }

    server {
        listen       84;
        server_name  127.0.0.1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
		
        location / {
            root   html;
            index  index.html index.htm;
        }

        #文件预览下载
		location ^~ /download/ {
			alias /home/test/file/uploads/;
		}
		
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }
	

}

#文件预览下载
location ^~ /download/ {
     alias /home/test/file/uploads/;
}

比如说数据库中存储的文件是/download/aaa.png, alias 表示别名,此配置则表示将/download/替换为/home/test/file/uploads/,然后通过文件名称找到相应的文件,进行预览。

配置springcloud项目 ,同时配置PC端和h5端的页面访问

#pid        logs/nginx.pid;

events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    underscores_in_headers on;
    #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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
	# 配置nginx上传文件最大限制
    client_max_body_size 100m;

    #gzip  on;
    gzip on;
    gzip_buffers 32 4K;
    gzip_comp_level 6;
    gzip_min_length 100;
    gzip_types application/javascript text/css text/xml;
    gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
    gzip_vary on;

    upstream proxy_store {
       #ip_hash;
       hash $remote_addr consistent;
       server 127.0.0.1:48081;     #业务逻辑,网关地址
    }

    upstream proxy_store_upload {
       #ip_hash;
       hash $remote_addr consistent;
       server 127.0.0.1:48080;     #业务逻辑,后台服务地址
    }

    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }
	
	#pc端
    server {
        listen       8180;
        server_name  test.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


        location / {
            #add_header 'Access-Control-Allow-Origin' *;
            #add_header 'Access-Control-Allow-Credentials' 'true';
            #add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            #add_header 'Access-Control-Allow-Headers' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
            #add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
            #if ($request_method = 'OPTIONS') {
            #    add_header 'Access-Control-Max-Age' 1728000;
            #    add_header 'Content-Type' 'text/plain; charset=utf-8';
            #    add_header 'Content-Length' 0;
            #    return 204;
            #}
            
            root   html;   #前端文件地址
            index  index.html;
        }
        
        #后台服务访问前缀
        location ^~/basic-api/ {
            proxy_pass http://proxy_store/;
            proxy_set_header Host    $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
		
		location ^~/basic-file/ {
            proxy_pass http://proxy_store_upload/;
            proxy_set_header Host    $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

        #文件上传路径
        location /upload {
            proxy_pass http://proxy_store_upload/admin-api/infra/file/upload;
            proxy_set_header Host    $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

    }
	
	server {
        listen       8181;
        server_name  test.com;
		#rewrite ^(.*)$  https://${server_name}$1 permanent;  # http转https
	
        #charset koi8-r;
	
        #access_log  logs/host.access.log  main;
	
        location / {
           
            root   htmlApp;   #h5前端文件地址
            index  index.html;
        }
        
        location ^~/api/ {
            proxy_pass http://proxy_store/;
            proxy_set_header Host    $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
	
        location /upload {
            proxy_pass http://proxy_store_upload/admin-api/infra/file/upload;
            proxy_set_header Host    $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
	
    }
	

}

 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐