一、 环境
Linux操作系统:centos6.9
Tomcat版本: tomcat7
Nginx版本: nginx/1.14.0
二、 配置步骤
1、 nginx.conf 配置文件内容
user root;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf; #包含其他的配置文件
}
2、 在conf.d配置文件夹下新建tomcat.conf 监听443端口,转发到tomcat服务器上
upstream tomcat_server{
server localhost:8080; #tomcat 服务
}
server {
listen 443; #监听443端口
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
proxy_pass http://tomcat_server; #转发到tomcat服务器上
}
#error_page 404 /404.html;
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
3、 重启nginx服务,检测tomcat服务是否开启
[root@VM_0_11_centos conf.d]# service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
4、 浏览器访问443端口
ip地址 : 443