0

再会。我有 nginx 服务器,它运行 https 连接。目前所有 URL 都使用 https 运行。我所需要的只是 - 从 https 中排除一些 URL,以便可以使用简单的 http 访问它们。这是我的 NGINX 配置文件:

server {
       listen           80;
       server_name              my-fin.ru www.my-fin.ru;

        root         /usr/server/finance/abacus/webapp;

        location ~ ^/.+\.(eot|ttf|woff)$ {
            expires max;
            add_header Cache-Control public;
            add_header Access-Control-Allow-Origin *;
        }

        location ~ ^/.+\.(ico|jpg|jpeg|gif|pdf|jar|png|js|css|txt|epf|svg)$ {
            expires max;
            add_header Cache-Control public;
        }

        location / {
               return                   301 https://my-fin.ru;
        }

}

server {
        listen          *:443;
        server_name     my-fin.ru;
        client_max_body_size 10m;
        gzip                    on;
        gzip_min_length 500;
        gzip_buffers    4 8k;
        gzip_types              text/plain text/xml application/xml application/x-javascript text/javascript text/css text/json application/json;

        access_log  /var/log/nginx/finance.access.log;
        error_log   /var/log/nginx/finance.error.log;

        ssl on;
        ssl_certificate         /usr/server/myfin.crt;
        ssl_certificate_key     /usr/server/myfin.key;
        charset                 utf-8;

        root         /usr/server/finance/abacus/webapp;

        location ~ ^/.+\.(eot|ttf|woff)$ {
            expires max;
            add_header Cache-Control public;
            add_header Access-Control-Allow-Origin *;
        }

        location ~ ^/.+\.(ico|jpg|jpeg|gif|pdf|jar|png|js|css|txt|epf|svg)$ {
            expires max;
            add_header Cache-Control public;
        }

        location / {
                # give site more time to respond
                proxy_read_timeout 120;
                proxy_pass        http://127.0.0.1:8087;
                proxy_redirect          http:// $scheme://;

                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr ;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
        }

}

请帮助配置nginx。

4

1 回答 1

1

根据这个评论,我会这样做。

## non https server
server {
    #non ssl server
    listen 80;
    server_name example.com;
    root /path/to/root;
    location /features {
        #handle /features
    }
    location /info {
        # handle /info
    }
    location /help {
        #handle /help
    }
    location /
        return 301 https://example.com$request_uri;
    }
}
## https server
server {
    # handle ssl
    listen 443 ssl;
    server_name example.com subdomain1.example.com;
    root /path/to/root;
    location ~ /(features|help|info) {
        # redirect those 3 subfolders to http
        return 301 http://example.com$request_uri;
    }
    location / {
        #handle ssl requests;
    }
}
## https subdomain
server {
    listen 443 ssl;
    server_name subdomain2.example.com;
    root /path/to/root;
    location ~ /(features|help|info) {
        # redirect those 3 subfolders to http
        return 301 http://example.com$request_uri;
    }
    location / {
        # subdomain handling
    }
}

请注意,除非您拥有通配符 SSL 证书,否则 https 不会在子域上工作,否则浏览器会发出警告。

于 2013-06-21T08:49:52.153 回答