大网数据广告活动
服务器运维问答

How to configure https with nginx with a public ip without domain name

· 52CE 我爱测

I have a public IP (for eg: 123.123.123.123) and I would like to install the ssl on a nginx server (for using https). I have a folder in /etc/nginx/ssl where I store my .crt and .key . Here is my nginx.conf : user nginx; worker_p…

问题原文

原帖链接 · executable · CC BY-SA 4.0

I have a public IP (for eg: 123.123.123.123) and I would like to install the ssl on a nginx server (for using https). I have a folder in /etc/nginx/ssl where I store my .crt and .key. Here is my nginx.conf :

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {

    server_tokens off;
    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;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    client_max_body_size 2M;

    include /etc/nginx/conf.d/*.conf;

    server {
        #listen       443 ssl http2 default_server;
        #listen       [::]:443 ssl http2 default_server;
        listen 443 ssl;
        server_name  _;
        root         /usr/share/nginx/html;


        add_header X-Frame-Options "SAMEORIGIN";

        ssl_certificate "/etc/nginx/ssl/site_bundle.crt";
        ssl_certificate_key "/etc/nginx/ssl/site.key";
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
        ssl_prefer_server_ciphers on;
        ssl_dhparam /etc/nginx/ssl/dhparam.pem;

        location / {
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
}

I have the following error :

In my SSL folder I have different files but I don't know wich one to use :

 - 12ae1782cad698c6.crt
 - a61d9dc8af1i5477.crt
 - dhparam.pem
 - gd_bundle-g2-g1.crt
 - domain_bundle.crt
 - domain.key

I got this message from my browser about the certificate

已采纳解答

原帖链接 · garethTheRed · CC BY-SA 4.0

There are at least three obvious issues here.

The NET::ERR_CERT_COMMON_NAME_INVALID tells you that the name in the certificate doesn't match the name you've requested in your browser. That makes complete sense as the certificate has a CommonName of *.domain.com while you're requesting by IP address. They will never match. You don't give enough information in your question to allow me to suggest a resolution, but as the error message suggests, the names must match. Either you have to have a DNS name instead of IP or a certificate with an IP address instead of a name.

Note that modern browsers don't actually use the CommonName in the certificate (even though the error message implies that they do). Instead they use the SubjectAlternativeName extension, which you can see if you click on the Details tab and scroll down.

Additionally, your certificate is only valid between 15th August 2017 and 15th August 2018. As I write this, it's the 15th February 2019, which doesn't fit between those two dates. That is, your certificate has also expired.

Your browser returns a 403 - Forbidden. Check the file permissions on the web root (/usr/share/nginx/html) to make sure they're readable by the user/group running nginx. Maybe www-data, depending on your distro.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-02-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。