乐云主机笔记

  • 首页
  • 学习记录
  • 资源下载
  • 新手教程
  • 其他
  • 脚本源码
  • 自用主机
  • 主机优惠
  • 域名优惠
  • 网赚项目

  1. 首页
  2. 新手教程
  3. 正文

Nginx 配置文件备忘单

2021年 11月 27日 932点热度 0人点赞 0条评论

Nginx 是用于 Web 服务、反向代理、缓存、负载平衡、媒体流等的开源软件。在这篇文章中,我将提到一些我们经常使用的 Nginx 配置。

 

监听端口

server {

# Standard HTTP Protocol

listen 80;

# Standard HTTPS Protocol

listen 443 ssl;

# For http2

listen 443 ssl http2;

# Listen on 80 using IPv6

listen [::]:80;

# Listen only on using IPv6

listen [::]:80 ipv6only=on;

}

访问日志

server {

# Relative or full path to log file

access_log /path/to/file.log;

# Turn 'on' or 'off'

access_log on;

}

域名

server {

# Listen to yourdomain.com

server_name yourdomain.com;

# Listen to multiple domains

server_name yourdomain.com www.yourdomain.com;

# Listen to all domains

server_name *.yourdomain.com;

# Listen to all top-level domains

server_name yourdomain.*;

# Listen to unspecified Hostnames (Listens to IP address itself)

server_name "";

}

静态资源

server {

listen 80;

server_name yourdomain.com;

location / {

root /path/to/website;

}

}

重定向

server {

listen 80;

server_name www.yourdomain.com;

return 301 http://yourdomain.com$request_uri;

}

server {

listen 80;

server_name www.yourdomain.com;

location /redirect-url {

return 301 http://otherdomain.com;

}

}

反向代理

server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://0.0.0.0:3000;

# where 0.0.0.0:3000 is your application server (Ex: node.js) bound on 0.0.0.0 listening on port 3000

}

}

负载均衡

upstream node_js {

server 0.0.0.0:3000;

server 0.0.0.0:4000;

server 123.131.121.122;

}

server {

listen 80;

server_name yourdomain.com;

location / {

proxy_pass http://node_js;

}

}

SSL协议证书

server {

listen 443 ssl;

server_name yourdomain.com;

ssl on;

ssl_certificate /path/to/cert.pem;

ssl_certificate_key /path/to/privatekey.pem;

ssl_stapling on;

ssl_stapling_verify on;

ssl_trusted_certificate /path/to/fullchain.pem;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_session_timeout 1h;

ssl_session_cache shared:SSL:50m;

add_header Strict-Transport-Security max-age=15768000;

}

# Permanent Redirect for HTTP to HTTPS

server {

listen 80;

server_name yourdomain.com;

return 301 https://$host$request_uri;

}

 

原文https://www.kejiwanjia.com/jiaocheng/41452.html

标签: 暂无
最后更新:2021年 11月 27日

wangzhe12588

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。

搜一搜

归档

  • 2025 年 8 月
  • 2025 年 7 月
  • 2025 年 6 月
  • 2025 年 5 月
  • 2025 年 4 月
  • 2025 年 3 月
  • 2025 年 2 月
  • 2025 年 1 月
  • 2024 年 12 月
  • 2024 年 11 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 7 月
  • 2024 年 3 月
  • 2024 年 2 月
  • 2024 年 1 月
  • 2023 年 12 月
  • 2023 年 11 月
  • 2023 年 10 月
  • 2023 年 9 月
  • 2023 年 8 月
  • 2023 年 7 月
  • 2023 年 6 月
  • 2023 年 5 月
  • 2023 年 4 月
  • 2023 年 3 月
  • 2023 年 2 月
  • 2023 年 1 月
  • 2022 年 12 月
  • 2022 年 11 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 8 月
  • 2022 年 7 月
  • 2022 年 6 月
  • 2022 年 5 月
  • 2022 年 4 月
  • 2022 年 3 月
  • 2022 年 2 月
  • 2022 年 1 月
  • 2021 年 12 月
  • 2021 年 11 月
  • 2021 年 10 月
  • 2021 年 9 月
  • 2021 年 8 月
  • 2021 年 7 月
  • 2021 年 6 月
  • 2021 年 5 月
  • 2021 年 4 月
  • 2021 年 3 月
  • 2021 年 2 月
  • 2021 年 1 月
  • 2020 年 12 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 9 月
  • 2020 年 8 月
  • 2020 年 7 月
  • 2020 年 6 月
  • 2020 年 5 月
  • 2020 年 4 月
  • 2020 年 3 月
  • 2020 年 2 月
  • 2020 年 1 月
  • 2019 年 12 月
  • 2019 年 11 月
  • 2019 年 10 月
  • 2019 年 9 月
  • 2019 年 8 月
  • 2019 年 7 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 4 月
  • 2019 年 3 月
  • 2019 年 2 月
  • 2019 年 1 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 9 月
  • 2018 年 8 月
  • 2018 年 7 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 2 月
  • 2017 年 12 月
  • 2017 年 11 月
  • 2017 年 10 月
  • 2017 年 9 月
  • 2017 年 8 月
  • 2017 年 7 月

分类

  • 主机优惠
  • 其他
  • 域名优惠
  • 学习记录
  • 新手教程
  • 网赚项目
  • 脚本源码
  • 自用主机
  • 资源下载

COPYRIGHT © 2021 Letcloud.cn. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

粤ICP备15031609号-3

粤公网安备(备案中)