技术解析

问个 nginx 配置二级域名的问题
0
2021-05-21 03:48:41
idczone

想把 api.example.com 解析到 123.123.123.123:8080/api 下

nginx 我已经配置了 api.example.com 123.123.123.123:8080

那个 /api 应该在哪里配置

upstream api__upstream {
    server 127.0.0.1:8080;
    keepalive 64;
}
server {
    listen 443 ssl;
    ssl_certificate "/etc/nginx/cert/api.pem";
    ssl_certificate_key "/etc/nginx/cert/api.key";
    ssl_protocols SSLv2 SSLv3 TLSv1;
    ssl_session_timeout 5m;
    ssl_prefer_server_ciphers on;
    ssl_ciphers ALL:!ADH:!E大带宽服务器XPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
    server_name api.xxx.com;
    access_log /root/nginx.log;
    location / {
        proxy_pass http://api__upstream;
        proxy_set_header   X-Real-IP            $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_set_header   X-NginX-Proxy    true;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }
}
server {
   listen 80;
   server_name api.xxxx.com;
   return 301 https://$server_name$request_uri;
}
    

去网上搜不知道应该按什么关键字搜这个问题 →_→


proxy_pass http://api__upstream/api;

靠,你在逗我
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
不应该是
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
然后删
ssl_prefer_server_ciphers on;
还有
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

现在都 2017 年了,还有人用 SSLv2 SSLv3
那个做教程的人也不应该把什么加密协议 /套件写死

我是在阿里云申请的免费 HTTPS 证书,二级域名的那个确实给的是 SSLv2 SSLv3 TLSv1 ,根域名是 TLSv1.2 TLSv1.1 TLSv1 。不安全?

试了一下,可以的, api 后边再加个“/”。棒棒哒 !

不建议使用 SSLv2 SSLv3 印象中好像是著名的心血漏洞什么的~
像我这种小白,用这个生成 nginx 配置文件 https://mozilla.github.io/server-side-tls/ssl-config-generator/
安利给楼主试试
不懂乱说光速逃跑 : )

rewrite ^(.*)$ http://api.example.com/api$1 permanent;

当然不安全
用 SSLv2 就是找死,参考 DROWN 攻击 ( https://drownattack.com/ ),不仅是开启 SSLv2 的机器本身会泄密,别的机器,只要使用一样的 RSA 密钥,就算你用 TLSv1.2 一样泄密。
SSLv3 是 POODLE 攻击 ( https://censys.io/blog/poodle ),没有 SSLv2 严重,但是与任何 CBC 模式的块加密算法 (比如 AES-CBC, 3DES-EDE-CBC) 使用就会泄密,除非使用 RC4 ,问题是 RC4 也不安全( https://www.rc4nomore.com/ ),一个 cookie 在一个普通电脑上 75 小时破解
不是什么 Heartbleed ,那个漏洞由于大家都很重视,基本上不存在了

https://mozilla.github.io/server-side-tls/ssl-config-generator/
server {
listen 80 default_server;
listen [::]:80 default_server;
Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
ssl_certificate /path/to/signed_cert_plus_intermediates;
ssl_certificate_key /path/to/private_key;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
ssl_dhparam /path/to/dhparam.pem;
intermediate configuration. tweak to your needs.
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
ssl_prefer_server_ciphers on;
HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;
OCSP Stapling ---
fetch OCSP records from URL in ssl_certificate and cache them
ssl_stapling on;
ssl_stapling_verify on;
verify chain of trust of OCSP response using Root CA and Intermediate certs
ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;
resolver ;
....
}

数据地带为您的网站提供全球顶级IDC资源
在线咨询
专属客服