Welcome! Log In Create A New Profile

Advanced

Apache to Nginx conversion does not work

Posted by gdosaigues 
Apache to Nginx conversion does not work
November 05, 2016 05:21AM
Hello,

this is driving me nuts.
My scenario is an apache2 and a tomcat with several webapps in it.

Actually, with apache+tomcat is working fine but I want to migrate to nginx to increase the performance and consume less resources.
This is one of the VirtualHost in apache:
<VirtualHost *:80>
ServerAdmin mail@gmail.com
ServerName webapp.com
ErrorLog logs/webapp-error_log
CustomLog logs/webapp-access_log common
ProxyPass / http://localhost:8081/DataFormSender/
ProxyPassReverse / http://localhost:8081/DataFormSender/
</VirtualHost>

In this case I need to redirect to http, but in others is https.

Webapps are done with J2EE, using spring security.
The problem is that nginx is unable to find static resources (images, css, js, ...) I tried everything but nothing worked.
To define the path of the resources I do this way:

<link href="<c:url value="/resources/css/generic.css" />" rel="stylesheet" type="text/css" />

The generated URL is correct, but is returning a 404 error message.
I understand that spring security is not the problem because the message is not 403.

This is the nginx translation of the apache virtualhost
server {
listen 80;
server_name webapp.com;
error_log logs/webapp-error_log warn;
allow all;
proxy_redirect / http://localhost:8081/DataFormSender/;

#
# This should be changed to whatever you config to real server.
#
root /var/tomcat/webapps/DataFormSender/resources;

log_format format_3 'common';
access_log logs/webapp-access_log format_3;
location / {
proxy_pass http://localhost:8081/DataFormSender/;
}
}

Any idea to solve this weird problem? Thank you for your time
Re: Apache to Nginx conversion does not work
November 05, 2016 03:07PM
Ok, I found a partial solution:

server {
listen 80;
server_name mdd.cat;
rewrite ^/MyApp/(.*)$ /$1 last;

location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8081/MyApp/;
}
}

Now, is finding static resources, but when I try to login in my app is always displaying the login page.
This is the url to access to login page: http://mdd.cat/login
And this is the url after successful login: http://mdd.cat/login;jsessionid=8E1070C32C43260F294D1350233A06FA

Any idea why its happening this?
Thanks!!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 128
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready