V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Newyorkcity
V2EX  ›  问与答

让 nginx 监听 443 并提供 https 服务 这样配置为啥不行呢?

  •  
  •   Newyorkcity · 2020-08-03 23:09:30 +08:00 · 1903 次点击
    这是一个创建于 1352 天前的主题,其中的信息可能已经有所发展或是发生改变。
    server {
        listen              443 ssl;
        server_name         xxx.yyy;
        ssl_certificate     /etc/nginx/ssl/1_xxx.yyy_bundle.crt;
        ssl_certificate_key /etc/nginx/ssl/2_xxx.yyy.key;
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
    
        root /var/www/html;
    
        index index.html;
    
        location / {
    		try_files $uri $uri/ =404;
    	}
    }
    

    http://nginx.org/en/docs/http/configuring_https_servers.html nginx 配置 https 官网给的前面半段的配置项,后面的是从 /etc/nginx/sites-avaliable/default 文件抄的。

    上面这段代码单独地写在 /etc/nginx/sites-avaliable/https 中,然后用了一个软连接 ln -s /etc/nginx/sites-avaliable/https /etc/nginx/sites-enable/ ,就像 debian 社区里介绍安装和使用 nginx 一样。我安装也是看这个的,debian 9,用 apt-get 装的。。

    netstat -nlp 看不到监听 443 的进程。

    谢谢解惑

    第 1 条附言  ·  2020-08-04 00:23:38 +08:00
    感谢各位相助 实际问题比较弱智 就是使用软连接的时候我使用了相对路径 然后在帖子里因为帖子上不存在相对环境而用了绝对路径
    9 条回复    2020-08-04 00:21:21 +08:00
    momocraft
        1
    momocraft  
       2020-08-03 23:13:05 +08:00
    確定被 include 了嗎?
    serco
        2
    serco  
       2020-08-03 23:13:05 +08:00
    nginx 启动了吗?修改配置后 reload 了吗?
    myd
        3
    myd  
       2020-08-03 23:13:16 +08:00 via Android
    启动 nginx 的时候没报错吗
    Newyorkcity
        4
    Newyorkcity  
    OP
       2020-08-03 23:14:53 +08:00
    @momocraft 应该 include,nginx.conf 我没改动过,`include /etc/nginx/sites-enabled/*;` 这句话也好好的放在文件里


    @serco systemctl restart nginx 了
    @myd 没有 nginx -t 表示配置没什么问题 systemctl restart nginx 是什么输出都没有
    dtgxx
        5
    dtgxx  
       2020-08-03 23:20:14 +08:00   ❤️ 1
    目录不一样,你 include 的是`include /etc/nginx/sites-enabled/*, 你的路径是 /etc/nginx/sites-enable/ 少个 d
    shc
        6
    shc  
       2020-08-03 23:32:54 +08:00
    `nginx -t`测试一下配置文件有没有检测通过
    Newyorkcity
        7
    Newyorkcity  
    OP
       2020-08-03 23:35:10 +08:00
    @dtgxx 感谢,不过只是我在发帖的时候少打了,真实文件位置的话是有那个 d 的,不过还是感谢你的细心查看和热心


    @shc

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

    nginx -t 的结果如上,应该没问题吧。。
    gstqc
        8
    gstqc  
       2020-08-04 00:01:07 +08:00   ❤️ 1
    nginx -T
    可以打印所有配置
    Newyorkcity
        9
    Newyorkcity  
    OP
       2020-08-04 00:21:21 +08:00
    @gstqc 感谢 从打印的结果上来看我配置的 server 确实没有被引入。我查了一下发现原来是我在设置软连接的时候使用了相对路径导致的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1097 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 18:36 · PVG 02:36 · LAX 11:36 · JFK 14:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.