标签 - ssl

nginx web ssl https    2021-08-23 11:46:54    15    0    0

对我来说nginx就是两个作用,(1)当个WEB服务器用(2)给其它WEB应用走https

一、用docker安装nginx

  1. docker pull nginx
  2. docker run -it -d --name mynginx --privileged --net=host nginx

二、配置nginx.conf

  1. user nginx;
  2. worker_processes auto;
  3. error_log /var/log/nginx/error.log notice;
  4. pid /var/run/nginx.pid;
  5. events {
  6. worker_connections 1024;
  7. }
  8. http {
  9. include /etc/nginx/mime.types;
  10. default_type application/octet-stream;
  11. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  12. '$status $body_bytes_sent "$http_referer" '
  13. '"$http_user_agent" "$http_x_forwarded_for"';
  14. access_log /var/log/nginx/access.log main;
  15. sendfile on;
  16. #tcp_nopush on;
  17. keepalive_timeout 65;
  18. #gzip on;
  19. include /etc/nginx/conf.d/*.conf;
  20. server {
  21. listen 443 ssl;
  22. server_name 13ua.com;
  23. ssl on;
  24. ssl_certificate /usr/share/nginx/html/13
ssl https leanote    2019-03-24 13:08:17    61    0    0

自架设了leanote,其中邮箱配置一直不成功,去官群问了一下,只得到了一个莫明的提示:“和ssl”有关。也没说清是邮箱ssl还是leanote网站https需要的那个ssl。

好吧得不到更详细的答案那就自己搞

让leanote走https

  1. 去申请个证书(略)
  2. 修改app.conf

    1. http.ssl = false 改为true
    2. #添加以下两行,path改成你存放证书的地址
    3. http.sslcert=/path/domain.crt
    4. http.sslkey=/path/domain.key
  3. 重启leanote

注意

  • 如果从阿里云下载来的for nginx的证书文是.pem和.key,那么上面添加的要改成下面这样
  1. http.sslcert=/path/domain.pem
  2. http.sslkey=/path/domain.key

注意2(这步我没用到)

  • 如果上面这样设置还不行,那就再添加下面
  • 添加文件 leanote/app/init.go
  1. #其中8889改成你的app.conf中一样的端口
  2. httpRedirectServer := &http.Server{Addr: ":8899", Handler: http.HandlerFunc(
  3. func(w http.ResponseWriter, r *http.Request) {
  4. http.Redirect(w, r, fmt.Sprintf("https://%s%s", r.Host, r.RequestURI),
  5. http.StatusMovedPermanently)
  6. })}
  7. go httpRedirectServer.ListenAndServe()

失望了

  • 邮箱问题依旧

    • 今天2022.11.18,邮件无意见解决了,具体看这里