-
侦听端口
server { # 监听端口 listen 80; # 标砖 HTTPS 协议 listen 443 ssl; # http2 listen 443 ssl http2; # 收听80使用IPv6 listen [::]:80; # 只在使用IPv6时收听 listen [::]:80 ipv6only=on; }
访问日志
server { # 日志文件 access_log /var/log/nginx/access.log; # 'on' 打开 或 'off' 关闭 access_log on; }
域名
server { # 绑定监听域名 server_name beixuan.com; # 监听 所有后缀匹配的 域名 server_name *.beixuan.com; # 监听所有 前缀匹配的域名 server_name beixuan.*; # 监听未指定的主机名(监听IP地址本身) server_name ""; }
静态资产
server { listen 80; server_name beixuan.com; # 访问地址 location / { # 静态页面文件路径 root /usr/share/nginx/html; } }
重定向
server { listen 80; server_name www.beixuan.com; return 301 http://beixuan.com$request_uri; } server { listen 80; server_name www.beixuan.com; location /redirect-url { return 301 http://otherbeixuan.com; } }
反向代理
server { listen 80; server_name beixuan.com; location / { # 绑定监听ip下的端口 proxy_pass http://111.67.192.246:8080; } }
负载均衡
upstream node_js { server 0.0.0.0:8000; server 0.0.0.0:9000; server 111.67.192.246; } server { listen 80; server_name beixuan.com; location / { proxy_pass http://new_vue; } }
SSL 协议
server { listen 443 ssl; server_name beixuan.com; ssl on; ssl_certificate /etc/pki/nginx/server.crt; ssl_certificate_key /etc/pki/nginx/private/server.key; ssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate /etc/pki/nginx/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; } # 永久重定向HTTP到HTTPS server { listen 80; server_name beixuan.com; return 301 https://$host$request_uri; }
nginx配置
最新推荐文章于 2024-06-11 14:52:14 发布