参考:Nginx 从入门到实践,万字详解!
设置反向代理
- 在nginx配置文件目录conf.d(一般路径为/etc/nginx/conf.d)中添加一个配置文件,例如叫twikoo.conf,文件内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| server { listen 80; server_name twikoo.theelyj.com; return 301 https://$host$request_uri; }
server { listen 443 ssl; server_name twikoo.theelyj.com;
ssl_certificate /etc/letsencrypt/live/theelyj.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/theelyj.com/privkey.pem;
location / { proxy_pass http://127.0.0.1:123456; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
|
这里表示将twikoo.theelyj.com网址(支持http和https协议)反向代理到服务器的12345端口,即访问twikoo.theelyj.com就相当于访问服务器的12345端口