🤖
AI审核中

READING IN THE WILD · 读一篇手记

Nginx线上配置https示例文件

文章摘要

本文提供了一个完整的 Nginx HTTPS 配置示例。全局设置包括日志、连接数、文件发送等;在 `http` 块中定义日志格式和基本参数。`server` 块一监听 443 并启用 SSL,指定域名、证书路径、私钥,并通过 `proxy_pass` 将请求转发至后端 IP+端口,同时设置真实 IP 头。另设 80 端口 `server`,使用 `rewrite` 永久重定向所有请求到 HTTPS。最后通过 `include /etc/nginx/conf.d/*.conf` 加载其他配置文件。

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

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;

    # Server Configuration for hqxiaozou.top

    server {
      #监听443端口
      listen 443 ssl;
      #你的域名
      server_name www.hqxiaozou.top hqxiaozou.top; 
      #ssl证书的pem文件路径
      ssl_certificate  /SSL/hqxiaozou.top_bundle.pem;
      #ssl证书的key文件路径
      ssl_certificate_key /SSL/hqxiaozou.top.key;
        location / {
         proxy_pass  http://你的ip:端口号;
         #用户真实ip配置
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       }
    }
    server {
        listen 80;
        server_name www.hqxiaozou.top hqxiaozou.top;
        #将请求转成https
        rewrite ^(.*)$ https://$host$1 permanent;
   }

    # Include the rest of the files in the conf.d directory, if any.
    include /etc/nginx/conf.d/*.conf;
}
0 条评论

如果你觉得文章对你有帮助,那就请作者喝杯咖啡吧

评论区 0

头像
 0 条评论