I have a strange problem with a web application running in Tomcat as a deployable.

The html that user gets when finally being on https://my-url.com/admin tried to fetch multiple resources from the application deployed to Tomcat.

Now if the FIRST request to Tomcat is made via Nginx, one of the Javascript files fetched will have a

<html><head><title>301 Moved Permanently</title></head><body bgcolor="white"><center><h1>301 Moved Permanently</h1></center><hr><center>nginx/1.12.2</center></body></html>;

appended at the very end of the file. This breaks the whole page as we are quite reliant on Javascript. But if I would now restart Tomcat and make the first request straight against the application without going though Nginx, this line will not be appended. All requests afterwards will work as intended even though Nginx.

Here is the nginx conf:

user              nginx  nginx;

worker_processes  2;

pid        /var/run/nginx.pid;

worker_rlimit_nofile 1024;

events {
        worker_connections 512;

http {

        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        sendfile "on";
        client_max_body_size 20m;
        client_body_timeout 300s;
        client_body_in_file_only clean;
        client_body_buffer_size 16K;
        client_body_temp_path /tmp/client_body_temp;
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
        keepalive_timeout  65;
        gzip  on;
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k;
        gzip_http_version 1.1;
        gzip_min_length 256;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;

server {
  listen 443 ssl;

  ssl_certificate      /etc/ssl/certs/name.crt;
  ssl_certificate_key  /etc/ssl/private/name.key;
  ssl_session_cache shared:SSL:1m;
  ssl_prefer_server_ciphers   on;

  server_name my-url.com;

  location / {
    return 301 https://$host/admin$request_uri;

  location /admin {
    proxy_set_header    Host $host;
    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_set_header    X-Forwarded-Proto $http_x_forwarded_proto;
    proxy_redirect /admin/;

server {
    listen 80;
    server_name my-url.com;
    access_log /dev/null;
    return 301 https://$host$request_uri;

Would anyone have some idea on what is going on here that causes such issue?

  • Your configiration file indicates that you have a 301 redirect to https which inturn has a 301 redirect to a page with "admin"in the path. Jan 12, 2018 at 11:55
  • return 301 https://$host/admin$request_uri; should be return 301 https://$host/admin/$request_uri Jan 12, 2018 at 11:55
  • return 301 https://$host$request_uri; should be return 301 https://$host/$request_uri; Jan 12, 2018 at 11:56
  • The slash in the middle will create an infinite loop
    – inimene
    Jan 12, 2018 at 12:10
  • Did it a bit wrong at first. Anyways.... now that I changed it like you suggested, the problem keeps apprearing...
    – inimene
    Jan 12, 2018 at 13:01


You must log in to answer this question.

Browse other questions tagged .