Nginx反向代理

Posted at — 2022-01-06

/etc/nginx/conf.d/目录下新建一个.conf文件,键入以下内容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
server {
    listen 443 ssl;
    listen 80;
    server_name $Domain$; # $Domain$为你的域名,例如abc.chio.in,同时记得DNS解析
    ssl	on;
    ssl_certificate ~/ssl/ssl.pem; # ssl证书地址
    ssl_certificate_key ~/ssl/ssl.key; # ssl密钥地址

    location / {
        proxy_pass http://127.0.0.1:$port$; # $port$为你要代理的本地端口
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $host:$server_port;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}

刷新配置: nginx -s reload