nginx reverse proxy + Spring ResourceSupport produces wrong URL path prefix -
spring hateoas resourcesupport generating incorrect urls in responses. using tomcat spring , nginx reverse proxy.
spring generated url: http://localhost:8080/spring-ng-seed
project url: https://spring-ng-seed.dev/
(serves static content),
web api url: https://spring-ng-seed.dev/wapi/
all requests /wapi/
work fine spring hateoas's resourcesupport generating urls like: https://spring-ng-seed.dev/spring-ng-seed/foo/bar
instead of https://spring-ng-seed.dev/wapi/foo/bar
for example, self rel when call https://spring-ng-seed.dev/wapi/foo/bar
end https://spring-ng-seed.dev/spring-ng-seed/foo/bar
coming self rel incorrect.
/spring-ng-seed/foo/bar
should /wapi/foo/bar
in response links.
i not sure configured wrong, nginx, tomcat or spring cannot find on anywhere else.
i using angularjs on front end doubt problem lays front end rather nginx reverse proxy or tomcat.
can please?
nginx config:
server { charset utf-8; listen 80; listen 443 ssl; server_name www.spring-ng-seed.dev spring-ng-seed.dev; ssl on; ssl_certificate /users/reecefowell/projects/spring/spring-ng-seed/cert.pem; # path cacert.pem ssl_certificate_key /users/reecefowell/projects/spring/spring-ng-seed/server.key; # path privkey.pem ssl_protocols tlsv1 tlsv1.1 tlsv1.2; ssl_ciphers ecdh+aesgcm:dh+aesgcm:ecdh+aes256:dh+aes256:ecdh+aes128:dh+aes:ecdh+3des:dh+3des:rsa+aesgcm:rsa+aes:rsa+3des:!anull:!md5; ssl_prefer_server_ciphers on; location /wapi/ { proxy_pass http://localhost:8080/spring-ng-seed/; proxy_read_timeout 90; proxy_connect_timeout 90; # proxy_ssl_session_reuse off; proxy_redirect off; proxy_set_header host $http_host; proxy_set_header x-real-ip $remote_addr; proxy_set_header x-forwarded-proto https; proxy_set_header x-forwarded-prefix $http_x_forwarded_prefix; proxy_set_header x-forwarded-host $http_x_forwarded_host; proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for; proxy_set_header x-nginx-proxy true; proxy_set_header x-forwarded-protocol https; proxy_set_header x-forwarded-ssl on; proxy_set_header x-url-scheme https; } location / { root /users/reecefowell/projects/spring/spring-ng-seed/src/main/webapp/app/build; index index.html; } }
my tomcat configured via pom.xml file:
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <packaging>war</packaging> <groupid>spring-ng-seed</groupid> <artifactid>spring-ng-seed</artifactid> <version>1.0-snapshot</version> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencymanagement> <dependencies> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-framework-bom</artifactid> <version>4.0.5.release</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencymanagement> <dependencies> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-context</artifactid> </dependency> <dependency> <groupid>org.springframework</groupid> <artifactid>spring-webmvc</artifactid> </dependency> <dependency> <groupid>org.springframework.hateoas</groupid> <artifactid>spring-hateoas</artifactid> <version>0.12.0.release</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-core</artifactid> <version>2.4.0</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-annotations</artifactid> <version>2.4.0</version> </dependency> <dependency> <groupid>com.fasterxml.jackson.core</groupid> <artifactid>jackson-databind</artifactid> <version>2.4.0</version> </dependency> ... </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> <plugin> <groupid>org.apache.tomcat.maven</groupid> <artifactid>tomcat7-maven-plugin</artifactid> <version>2.2</version> <!--<configuration>--> <!--<url>http://localhost:8080/manager</url>--> <!--<server>localhost</server>--> <!--</configuration>--> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.4</version> </plugin> </plugins> </build> </project>
can please have @ proxy headers request contains when hits service. spring-hateoas process x-forwarded-prefix
header , prepend path.
have @ answer here: https://stackoverflow.com/a/36163242/5371736
Comments
Post a Comment