avatar

sunday

Sunday's Blog

  • 首页
Home nginx+acme申请证书
文章

nginx+acme申请证书

Posted 2021-06-5 Updated 2024-01- 2
By sunday
8~10 min read
  1. centos上执行以下命令
yum update #更新服务器一些依赖
yum install nginx #安装Nginx
nginx -c /etc/nginx/nginx.conf #执行这句之后reload不会报错
vim /etc/nginx/nginx.conf #打开nginx配置文件
#把里面的 server_name 改为你想要的域名
#下面继续安装acme
curl  https://get.acme.sh | sh #如果卡的话 ctrl+c 取消再执行,多试几次
cd ~/.acme.sh
./acme.sh --issue -d mydomain.com --nginx #替换mydomain.com为你的域名
#成功后会显示证书的路径,这里我们只需要 mydomain.key 和 fullchain.cer 把这两个的路径复制到nginx.conf上就配置成功了	

下面是nginx.conf的配置示例 以强制跳转https

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

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

events {
    worker_connections 1024;
}

http {
    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;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  mydomain.com;
	return 301 https://$server_name$request_uri;  
    }

# Settings for a TLS enabled server.
#
    server {
        listen       443 ssl http2 default_server;
        listen       [::]:443 ssl http2 default_server;
        server_name  _;
	#如果是配置静态网站 注解掉下面这行 改为你的网站
        #root         /usr/share/nginx/html;
        #这里是配置fullchain.cer的路径
        ssl_certificate "/root/.acme.sh/mydomain.com/fullchain.cer"; 
	#这里是配置mydomain.key的路径
        ssl_certificate_key "/root/.acme.sh/mydomain.com/mydomain.com.key";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;

#       include /etc/nginx/default.d/*.conf;
         
        location / {
		#配置静态网站注释掉下面这行,接口的话就像下面这样写
		proxy_pass http://127.0.0.1:8090;
        }

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

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

}
nginx
nginx acme 强制跳转HTTPS 代理
License:  CC BY 4.0
Share

Further Reading

Oct 30, 2024

nginx设置多个允许跨域的请求源

# 定义允许的源列表 map $http_origin $cors_origin { "https://youdomian.com" "https://youdomian.com"; "http://localhost:3010" "http://localhost:3010"; }

Apr 2, 2024

已安装的nginx,动态模块开启google brotli 压缩,并在vite项目中启用

1.下载ngx_brotli 到github https://github.com/google/ngx_brotli 然后git clone cd /usr/local/ git clone https://github.com/google/ngx_brotli.git cd /usr/loca

Apr 1, 2024

nginx1.25.0以上快速开启http3

nginx 快速开启http3 参考以下配置: server { listen 443 ssl; listen 443 quic reuseport; #开启http3特性 注意 reuseport 只能填写一次,比如你在另外个域名也是这样填写,会报duplicate的信息,ngin

OLDER

NEWER

mac上的一款SSH终端管理神器!

Recently Updated

  • nextjs15使用better-sqlite3的连接报错问题
  • nextjs + clerk + supabase + realtime 实时监听数据库更改
  • 解决nextjs15使用useLocalStorage报错的问题
  • mac上使用nodejs appium控制chrome浏览器
  • 2024年终总结

Trending Tags

nginx acme 强制跳转HTTPS nodejs 代理 mac 神器 vue3 工具 docker

Contents

©2025 sunday. Some rights reserved.

Using the Halo theme Chirpy