我有一个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)修改配置文件,如下所示
原文链接:https://www.f2er.com/nginx/435459.htmla)修改配置文件,如下所示
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的目录