简体   繁体   中英

Nginx redirect http to https for Alfresco share

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 https://new.domain.com/share/

I want to redirect all http traffic to https://new.domain.com/share/ . Tried changing the server config block but getting an error too many redirects .

currently new.domain.com is redirecting to https://new.domain.com/ and need to change it from new.domain.com to https://new.domain.com/share/

nginx.conf

#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] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    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;

    }

}
}

alfresco.conf

        # 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 "";
                        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 "";
                        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 "";
                        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 "";
                        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 "";
                        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;
                }
        }

Redirection code:

server {
    if ($host = new.domain.com) {
        return 301 https://$host$request_uri;
    }

    listen 80;
    listen [::]:80;
    server_name         new.domain.com;
    return 404;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM