我是靠谱客的博主 乐观楼房,最近开发中收集的这篇文章主要介绍nginx反向代理tomcat,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

nginx代理tomcat的配置如下:

server {
    listen       80;
    server_name  pns.weiyuexin.top;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
        proxy_pass http://1.15.60.193:8080;
    }

    #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   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ .php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ .php$ {
    #   root           html/www;
    #   fastcgi_pass   127.0.0.1:9000;
    #   fastcgi_index  index.php;
    #   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #   include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /.ht {
    #    deny  all;
    #}
}

重启nginx服务器:

image-20211124000937383

运行结果:

image-20211124000852279

配置SSL证书

server {
    listen       443 ssl;
     # 绑定证书的域名
    server_name  pns.weiyuexin.top;
    # 证书名称
    ssl_certificate     1_pns.weiyuexin.top_bundle.crt;
    # 私钥文件名称
    ssl_certificate_key    2_pns.weiyuexin.top.key;
    ssl_session_timeout  5m;
    # 协议配置
    ssl_protocols   TLSv1   TLSv1.1  TLSv1.2;
    ssl_ciphers  ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
        proxy_pass http://1.15.60.193:8080;
    }

    #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   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ .php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ .php$ {
    #   root           html/www;
    #   fastcgi_pass   127.0.0.1:9000;
    #   fastcgi_index  index.php;
    #   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #   include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /.ht {
    #    deny  all;
    #}
}

http重定向到https

server {
listen 80;
server_name pns.weiyuexin.top;
rewrite ^(.*) https://$server_name$1 permanent;  #http自动跳转到https
}

运行结果:

image-20211124124359080

最后

以上就是乐观楼房为你收集整理的nginx反向代理tomcat的全部内容,希望文章能够帮你解决nginx反向代理tomcat所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部