欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Windows下 配置Nginx+Tomcat

程序员文章站 2022-03-02 23:06:31
...

1.下载Nginx并解压到一个目录下,例如:D:\ApacheSoftware\Nginx

2.修改配置文件conf/nginx.conf,

在http {}中的最后面加上include vhost/*.conf;

http{   
#其他配置
include vhost/*.conf;
}

3.在conf目录下新建 vhost目录,在vhost目录下面新建  文件名.conf的文件,文件名自定义,一般采用域名对其进行命名。

配置内容如下:

upstream  192.168.0.102{
server  192.168.0.102:8081;
}

server {
	listen 8080;
	server_name 192.168.0.102;
	access_log  logs/pandora_sale_access.log;
	error_log   logs/pandora_sale_error.log;
	#root D:\ApacheSoftware\Nginx\nginx-1.13.8\html\host1;
	location / {
		client_max_body_size  0;
		gzip  off;
		proxy_pass http://192.168.0.102;
		proxy_set_header  X-Real-IP $remote_addr;
		proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header  Host $http_host;

	}
}

其中server  192.168.0.102:8081是Tomcat的访问路径

upstream和proxy_pass后的IP地址保持一致,server_name 为访问域名,可以配置为IP地址

最后重启Nginx就可以了

nginx -s reload

相关标签: web服务器