nginx非80端口单tomcat动静分离设置

nginx版本: windows版  nginx-1.9.12

nginx 为85端口, tomcat为8180端口, 项目的静态文件都在 statics目录下

worker_processes  1;

events {
    worker_connections  1024;
}

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

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       85;
        server_name  localhost;
		
		location / {
			proxy_pass http://localhost:8180;
			proxy_set_header Host $host:$server_port;
			proxy_redirect off;
			proxy_set_header X-Real-IP $remote_addr;
			proxy_set_header REMOTE-HOST $remote_addr;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_connect_timeout 60;
			proxy_read_timeout 600;
			proxy_send_timeout 600;
		}

		location ^~ /statics/ {
			root   html/DTS;
		}
    }

}

注意:1.proxy_pass 的地址不能以“/”结尾

2.如果为默认80端口$server_port可以不用设置

3.将项目statics目录下的文件拷贝到nginx的 html/项目名称 下

你可能感兴趣的:(nigix)