nginx 代理tomcat war包服务

#upstream tomcatserver{
  #      server 127.0.0.1:8080 weight=10;

#}

server {
        listen 80;
        listen [::]:80;
        #自动跳转到HTTPS(可选,和下面的部分域名跳转不能同时使用)
     if ($server_port = 80){
        rewrite ^(/.*)$ https://$host$1 permanent;
     }

        # SSL config
        # ration
        #
        listen 443 ssl default_server http2;
        listen [::]:443 ssl default_server http2;
        ssl_certificate Nginx/1_superting.cn_bundle.crt;
        ssl_certificate_key Nginx/2_superting.cn.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;

        server_name superting.cn;

#       location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
#               try_files $uri $uri/ =404;
#               #proxy_pass http://tomcatserver;
#       }
#      全文重点
        location /AssistedLearningSystem_war{
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://127.0.0.1:8080/AssistedLearningSystem_war;
        }

        # pass PHP scripts to FastCGI server
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        #}


          location ~.php($|/) {
                fastcgi_pass   127.0.0.1:9000;
                #fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

                fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
                fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
                fastcgi_param PATH_INFO $fastcgi_path_info;
                include fastcgi.conf;
                include        fastcgi_params;
            }

        #location /AssistedLearningSystem/{
        #       proxy_pass http://tomcatserver
        #}

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


# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#       listen 80;
#       listen [::]:80;
#
#       server_name example.com;
#
#       root /var/www/example.com;
#       index index.html;
#
#       location / {
#               try_files $uri $uri/ =404;
#       }
#}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
部署warnginx并不是nginx的主要功能,nginx主要用作web服务器的反向代理和负载均衡。war是Java Web应用程序的打格式,通常部署在Java应用服务器(如Tomcat)上。如果你想将war部署到nginx上,你需要先将war部署到一个Java应用服务器上,然后通过nginx配置反向代理来访问该应用服务器。 以下是一个简单的步骤来部署warnginx: 1. 首先,确保你已经安装了Java应用服务器(如Tomcat)并成功部署了war。 2. 然后,配置nginx的反向代理,将请求转发到Java应用服务器。你可以在nginx的配置文件中添加类似以下的配置: ``` location / { proxy_pass http://localhost:8080; # 将请求转发到Tomcat的默认端口8080 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } ``` 这个配置将所有的请求转发到本地的Tomcat服务器。 3. 保存并退出nginx的配置文件,然后重新加载nginx的配置文件,使配置生效。 4. 现在,你可以通过访问nginx的地址来访问部署在Tomcat上的war了。 请注意,这只是一个简单的示例,实际的配置可能会因为你的具体需求而有所不同。你可能需要根据你的实际情况进行适当的调整和配置。 希望这个回答对你有帮助!如果你还有其他问题,请随时提问。 #### 引用[.reference_title] - *1* *2* [Linux上 Nginx + Tomcat部署war(简单)](https://blog.csdn.net/kang389110772/article/details/59111287)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Linux服务器搭建及war部署](https://blog.csdn.net/weixin_43949154/article/details/124129027)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值