NGINX Config
Nginx Config 是一个强大的 Nginx 配置文件生成器,号称配置 Nginx 服务器所需的唯一工具。
项目地址:https://github.com/digitalocean/nginxconfig.io
Nginx 特性
高-效静态内容处理:Nginx能够以极少的资源服务大量的静态文件请求。 优-秀的反向代理能力:作为反向代理,Nginx能够平衡后端服务器的负载,从而提高应用的整体性能和稳定性。 负载均衡:通过智-能分配客户端请求到不同后端服务器,Nginx确保每个服务器都不会过载,同时提高整体的服务可用性。 内置缓存:Nginx可以缓存请求结果,减少对后端服务器的请求频率,加快响应速度。 原生SSL/TLS支持:可以处理加密的HTTPS请求,保障数据传输的安-全。 WebSocket支持:支持实时Web应用所需的WebSocket协议。
有很多功能和相应的配置指令。你现在可以深入研究NGINX文档,或者你可以使用这个工具来检查NGINX是如何工作的,观察你的输入是如何影响输出的,并为你的特定用例生成最佳配置(同时你也可以使用文档)。
NGINX Config 特点
Nginx Config 支持以下功能的可视化配置:HTTPS、HTTP/2、IPv6、certbot、HSTS、安全请求头、SSL 配置、OCSP 解析器、缓存、gzip、brotli、回退路由、反向代理、www/non-www 重定向、CDN、PHP(TCP/socket、 WordPress、Drupal、Magento、Joomla)、Node.js、Python (Django)
服务器等。
站点配置
全局配置
使用配置
配置文件
主配置
/etc/nginx/nginx.conf
# Generated by nginxconfig.io
# See nginxconfig.txt for the configuration share link
user www-data;
pid /run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65535;
# Load modules
include /etc/nginx/modules-enabled/*.conf;
events {
multi_accept on;
worker_connections 65535;
}
http {
charset utf-8;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
server_tokens off;
log_not_found off;
types_hash_max_size 2048;
types_hash_bucket_size 64;
client_max_body_size 16M;
# MIME
include mime.types;
default_type application/octet-stream;
# Logging
access_log off;
error_log /dev/null;
# SSL
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
# Diffie-Hellman parameter for DHE ciphersuites
ssl_dhparam /etc/nginx/dhparam.pem;
# Mozilla Intermediate configuration
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
resolver_timeout 2s;
# Load configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
次配置
/etc/nginx/sites-available/tinywan.com.conf
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name tinywan.com;
set $base /var/www/tinywan.com;
root $base/public;
# SSL
ssl_certificate /etc/letsencrypt/live/tinywan.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/tinywan.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/tinywan.com/chain.pem;
# security
include nginxconfig.io/security.conf;
# logging
access_log /var/log/nginx/access.log combined buffer=512k flush=1m;
error_log /var/log/nginx/error.log warn;
# index.php
index index.php;
# index.php fallback
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# additional config
include nginxconfig.io/general.conf;
# handle .php
location ~ \\\\.php$ {
fastcgi_pass unix:/var/run/php/php-fpm.sock;
include nginxconfig.io/php_fastcgi.conf;
}
}
# subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name *.tinywan.com;
# SSL
ssl_certificate /etc/letsencrypt/live/tinywan.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/tinywan.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/tinywan.com/chain.pem;
return 301 https://tinywan.com$request_uri;
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name .tinywan.com;
include nginxconfig.io/letsencrypt.conf;
location / {
return 301 https://tinywan.com$request_uri;
}
}
PHP 配置
/etc/nginx/nginxconfig.io/php_fastcgi.conf
# 404
try_files $fastcgi_script_name =404;
# default fastcgi_params
include fastcgi_params;
# fastcgi settings
fastcgi_index index.php;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
# fastcgi params
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE \\\"open_basedir=$base/:/usr/lib/php/:/tmp/\\\";
安全配置
/etc/nginx/nginxconfig.io/security.conf
# security headers
add_header X-XSS-Protection \\\"1; mode=block\\\" always;
add_header X-Content-Type-Options \\\"nosniff\\\" always;
add_header Referrer-Policy \\\"no-referrer-when-downgrade\\\" always;
add_header Content-Security-Policy \\\"default-src \\\'self\\\' http: https: ws: wss: data: blob: \\\'unsafe-inline\\\'; frame-ancestors \\\'self\\\';\\\" always;
add_header Permissions-Policy \\\"interest-cohort=()\\\" always;
add_header Strict-Transport-Security \\\"max-age=31536000; includeSubDomains\\\" always;
# . files
location ~ /\\\\.(?!well-known) {
deny all;
}
原创文章,作者:网络技术联盟站,如若转载,请注明出处:https://www.sudun.com/ask/49889.html