Nginx 将 http 重定向到 https 以进行 Alfresco 共享

Nginx redirect http to https for Alfresco share

我在 ubuntu 机器上安装了 alfresco 5.2 社区版,使用 nginx 作为代理。最近为我的新域更新了 SSL。它工作正常,可以通过 https://new.domain.com/share/

访问网站

我想将所有 http 流量重定向到 https://new.domain.com/share/。已尝试更改服务器配置块,但出现 错误太多重定向 .

目前 new.domain.com 正在重定向到 https://new.domain.com/ 并且需要将其从 new.domain.com 更改为 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;
                }
        }

重定向代码:

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

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

}