如何配置Glassfish NGINX使用NGINX提供静态文件?

前端之家收集整理的这篇文章主要介绍了如何配置Glassfish NGINX使用NGINX提供静态文件?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我有一个EC2 ubuntu和Glassfish v3 Nginx设置来托管我的java web应用程序.此应用程序作为WAR文件部署到Glassfish. Nginx当前将所有请求传递给glasshfish appserver,包括静态图像,css等javascripts等.

server {
  listen  80;
  server_name whatever.com www.whatever.com;

  access_log  /var/log/Nginx/whatever.com.access.log;

  location / {
    proxy_pass  http://127.0.0.1:8080/javapp/;
    proxy_pass_header Set-Cookie;
    proxy_pass_header X-Forwarded-For;
    proxy_pass_header Host;
  }

}

最佳答案
我已经解决了这个问题如下
a)修改配置文件,如下所示

server {

        listen   80; ## listen for ipv4
        server_name  www.whatever.com; ## change this to your own domain name
    root   /home/ubuntu/www/public_html;
## Only requests to our Host are allowed i.e. nixcraft.in,images.nixcraft.in and www.nixcraft.in
      if ($host !~ ^(www.whatever.com)$) {
         return 444;
      }


    location ~* \.(jpg|jpeg|gif|css|png|js|ico)${
        access_log off;
        expires max;
    }

    location / {
        access_log off;
        proxy_pass http://localhost:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
                root   /var/www/Nginx-default;
        }


}

b)在Nginx HTML根目录下(/ home / ubuntu / www / public_html)创建一个与web应用程序上下文同名的子目录.例如如果你的webpp网址是www.whatever.com/mycoolapp,请创建一个名为/ home / ubuntu / www / public_html / mycoolapp的目录

c)将war文件解压缩到此文件夹.摆脱WEB-INF文件

d)重启Nginx.要验证,请停止您的Web应用程序,同时保持Nginx并从您的webapp访问图像或css.

原文链接:https://www.f2er.com/nginx/435459.html

猜你在找的Nginx相关文章