---
title: "nginx+tomcat基本配置"
author: "小于Brick"
date: "2016-11-08T12:54:01Z"
tags: ["nginx"]
categories: ["开源软件"]
slug: "nginx-tomcat"
draft: false
lastmod: "2016-12-20T19:58:40Z"
id: 2336042
url: "https://youngbrick.iteye.com/blog/2336042"
---

nginx1.10.2安装：[http://youngbrick.iteye.com/blog/2336022](/blog/2336022 "http://youngbrick.iteye.com/blog/2336022")

tomcat8安装：[http://youngbrick.iteye.com/blog/2335305](/blog/2335305 "http://youngbrick.iteye.com/blog/2335305")

 

nginx基本配置

 修改nginx.conf 文件，只添加了3处：

 

```
[root@localhost /]#cd /usr/local
[root@localhost local]# vi ./nginx/conf/nginx.conf
```

 

```
http {
    #gzip  on;
    ############1###############
    upstream local_tomcat{
        这里是访问tomcat的端口
	server localhost:8080;
    }
    server {
        listen       80;
        ############2###############
        server_name www.abc.com域名;
        location / {
            root   html;
            index  index.html index.htm;
            ############3#头部配置也加上，不加有些系统不加访问不了。如果这里不是使用默认80端口，需要在这里配置$server_port##############
            proxy_set_header Host $host:$server_port;
            proxy_set_header X-Forwarded-For $remote_addr;
	    proxy_pass http://local_tomcat;
        }
xxxxxxxxxxxx略xxxxxxxxxxxxxxxx
    }
xxxxxxxxxxxx略xxxxxxxxxxxx
}
```

 

启动tomcat

```
[root@localhost local]# ./apache-tomcat-8.5.6/bin/startup.sh 
```

 

重启nginx

 

```
[root@localhost local]# ./nginx/sbin/nginx -s reload
```

 

 

开放80和443端口并重新加载：

 

```
[root@localhost local]# firewall-cmd --zone=public --add-port=443/tcp --permanent
success
[root@localhost local]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost local]# firewall-cmd --reload
```

 查看开放的端口：

 

 

```
[root@localhost local]# firewall-cmd --zone=public --list-ports
443/tcp 80/tcp
```

 浏览器访问：http://serverip/

能看到页面跳转到tomcat首页，说明配置成功。

 ![](http://dl.iteye.com/upload/picture/pic/136357/94c8762b-0d81-3ca8-a25e-8de19ad53fc9.jpg)