title: Nginx redirect http to https for Alfresco share
body: <p>I have alfresco 5.2 community edition installed on ubuntu machine with nginx as proxy. updated the SSL recently for my new domain. It is working fine and site is accessible through <a href="https://new.domain.com/share/" rel="nofollow noreferrer">https://new.domain.com/share/</a></p>
  <p>I want to redirect all http traffic to <a href="https://new.domain.com/share/" rel="nofollow noreferrer">https://new.domain.com/share/</a>. Tried changing the server config block but getting an <strong>error too many redirects</strong> .</p>
  <p>currently new.domain.com is redirecting to <a href="https://new.domain.com/" rel="nofollow noreferrer">https://new.domain.com/</a> and need to change it from new.domain.com to <a href="https://new.domain.com/share/" rel="nofollow noreferrer">https://new.domain.com/share/</a></p>
  <p>nginx.conf</p>
  <pre><code>#user nginx;
  #worker_processes auto;
  error_log /var/log/nginx/error.log;
  pid /var/run/nginx.pid;
  #events {
  #    worker_connections 1024;
  #}
  events {}
  http {
      log_format  main  '$remote_addr - $remote_user [$time_local] &quot;$request&quot; '
                        '$status $body_bytes_sent &quot;$http_referer&quot; '
                        '&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;';
  
      access_log  /var/log/nginx/access.log  main;
      include             /etc/nginx/mime.types;
      default_type        application/octet-stream;
      include /etc/nginx/conf.d/*.conf;
  
      index   index.html index.htm;
  
      server {
          listen       80 default_server;
          listen       [::]:80 default_server;
          server_name  new.domain.com;
          return 301 https://new.domain.com$request_uri;
         location / {
          error_page 404 /404.html;
              location = /40x.html {
          }
          error_page 500 502 504 /50x.html;
              location = /50x.html {
          }
      }
  }
  
  server {
      listen 443 default ssl;
  
      server_name  new.domain.com;
  
      access_log on;
      ssl on;
      ssl_certificate /etc/nginx/ssl/NEW.DOMAIN.COM.crt;
      ssl_certificate_key /etc/nginx/ssl/new.domain.com.key;
      location / {
          client_max_body_size 4000M;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-Proto https;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_pass http://127.0.0.1:8080;
          sub_filter_types text/javascript;
          sub_filter_once off;
  
      }
  
  }
  }
  
  </code></pre>
  <p>alfresco.conf</p>
  <pre><code>        # Set proxy cache path
          proxy_cache_path /var/cache/nginx/alfresco levels=1 keys_zone=alfrescocache:256m max_size=512m inactive=1440m;
          # Alfresco Repository Tomcat instance
          upstream alfresco {
                  server localhost:8080;
          }
  
          # Share Web client Tomcat instance
          upstream share {
              server localhost:8080;
          }
          # Default server config. Update server name.
          server {
                  listen        80 ;
                  listen   [::]:80 ;
                  server_name example.com www.example.com;
  
                  root /opt/alfresco/www;
                  index index.html index.htm;
  
                  # Redirect root requests to Share. Do not do this if you use AOS
                  # rewrite ^/$   /share;
  
                  # redirect server error pages to the static page /50x.html
                  #
                  error_page 502 503 504 /maintenance.html;
                          location = /maintenance.html {
                          root   /opt/alfresco/www;
                  }
  
                  # Access to old Alfresco web client. Remove this location if not needed.
                  location /alfresco {
  
                          # Allow for large file uploads
                          client_max_body_size 4000M;
  
                          # Proxy all the requests to Tomcat
                          proxy_http_version 1.1;
                          #proxy_buffering off;
                          proxy_pass http://alfresco;
  
                          proxy_set_header Proxy &quot;&quot;;
                          proxy_set_header Host $http_host;
                          proxy_set_header X-Real-IP $remote_addr;
                          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                          proxy_set_header X-Forwarded-Host $http_host;
                          proxy_set_header X-Forwarded-Server $host;
                  }
  
                  location /share {
  
                          # Allow for large file uploads
                          client_max_body_size 4000M;
  
                          # Proxy all the requests to Tomcat
                          proxy_http_version 1.1;
                          #proxy_buffering off;
                          proxy_pass http://share;
  
                          proxy_set_header Proxy &quot;&quot;;
                          proxy_set_header Host $http_host;
                          proxy_set_header X-Real-IP $remote_addr;
                          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                          proxy_set_header X-Forwarded-Host $http_host;
                          proxy_set_header X-Forwarded-Server $host;
                  }
  
                  location /share/proxy/alfresco {
                          # This section is for allowing to rewrite 50x response to 401 on Ajax req.
                          # This forces Share to reload page, and thus display maintenance page
  
                          # Allow for large file uploads
                          client_max_body_size 4000M;
  
                          # Proxy all the requests to Tomcat
                          proxy_http_version 1.1;
                          #proxy_buffering off;
                          proxy_pass http://share;
  
                          proxy_set_header Proxy &quot;&quot;;
                          proxy_set_header Host $http_host;
                          proxy_set_header X-Real-IP $remote_addr;
                          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                          proxy_set_header X-Forwarded-Host $http_host;
                          proxy_set_header X-Forwarded-Server $host;
                          proxy_intercept_errors on;
                          error_page 502 503 504 =401 /maintenance.html;
                  }
  
                  location /share/res/ {
  
                          # Proxy all the requests to Tomcat
                          proxy_http_version 1.1;
                          proxy_pass http://share;
                          proxy_set_header  Host $http_host;
  
                          proxy_set_header Proxy &quot;&quot;;
                          proxy_cache alfrescocache;
                          proxy_cache_min_uses 1;
                          proxy_cache_valid  200 302 1440m;
                          proxy_cache_valid  404 1m;
                          proxy_cache_use_stale updating error timeout invalid_header http_500 http_502 http_503 http_504;
                  }
  
                  location / {
                          # Allow for large file uploads
                          client_max_body_size 4000M;
  
                          # Proxy all the requests to Tomcat
                          proxy_http_version 1.1;
                          #proxy_buffering off;
                          proxy_pass http://alfresco;
  
                          proxy_set_header Proxy &quot;&quot;;
                          proxy_set_header Host $http_host;
                          proxy_set_header X-Real-IP $remote_addr;
                          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                          proxy_set_header X-Forwarded-Host $http_host;
                          proxy_set_header X-Forwarded-Server $host;
          }
  
                  location /downtime.js {
                          # Allow the maintenance page to pick up downtime.js script
                          root   /opt/alfresco/www;
                  }
          }
  
  </code></pre>