NGINX configure auto generator

The easiest way to configure a performant, secure, and stable NGINX server.

https://www.digitalocean.com/community/tools/nginx

demo

https://www.digitalocean.com/community/tools/nginx?domains.0.server.domain=xgqfrms.xyz&global.https.ocspCloudflareType=both&global.https.ocspGoogleType=both&global.https.ocspOpenDnsType=both

# Download the generated config: nginxconfig.io-xgqfrms.xyz.tar.gz
# and upload it to your server's/etc/nginx directory. # or, Copy a base64 string of the compressed config, paste it in your server's command line and execute it. $ echo 'H4sIAHNbUF8CA+0aaXPbuNWf9StQb6bZpMtbhyuNx+OxvbFn7NgTeTvb2bgciAQprEGAC4A6UmV/ex8PSaSOJO007hHD5qF3AQ94eHjAI48pn5mB4NHBVys2lF6vVzyhbD69Trt34Hg9t213Op2ud1CS28g+eIKSKY0lQgffaPkOvSGcSKxJiEZzxHNzyK2BxiYVre/QWOtU9S1rOp2aIY2pxkwEBHMwmcSCK8k41XNLC8GUVXCfhCLBlCvTNhWREyLNEnA8i3+LZKLM2fzDH2MmRpiZhXRTBCo9YyILI4YluZ+n5Hgk9Hib6I0QMfsUwW1K+DlXK4pWK4M2oM0Cyhgh1njQSmm4hUWWzHipiwn4QWsq5CORfipBc6WIKohwpsUKJRlNqPa5iCgjqNvpeJ1Bq0UmhGuF/t7K6ZOMaerjICCpruoRfFCgKiHQ7ZwEmgquliI+tlq5cpWIYIylIrrZ2ExHxlEpRxEeFg2ol2UlOkihfWmmxnuRIWF4vo0sR9HX4pFwtUJGUYllIgZW7Uci4+EWVsNIKH+M1dhP8MxX9AO0zrXbVYsDRqGLCtRIhPMS73RvoPNy9Hfo5urmonilPGBZ2FQNJTQhZlFFKS4kEYZu9nPQiginKaMBzvvVEoEm2lBaEpys6rgWMYx1XPzKx0cpH5Sq28MESwtApU1YJY0JgLJWIqWQGyybPAVNzoKmWPJV1cPhddnFivlgWAra6GtQSmQwyk442EIGOBgXqimwBRL2QUDfsZPBDinBIwHjK4eiqu6cRhElxiVhLMEcpVjihGiYIJGQ6PzyAgU0HROpMqqJW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EjrACwAAA==' | base64 --decode | tee /etc/nginx/nginxconfig.io-xgqfrms.xyz.tar.gz > /dev/null # Navigate to your NGINX configuration directory on your server:
$ cd /etc/nginx # Create a backup of your current NGINX configuration:
$ tar -czvf nginx_$(date +'%F_%H-%M-%S').tar.gz nginx.conf sites-available/ sites-enabled/ nginxconfig.io/ # Extract the new compressed configuration archive using tar:
$ tar -xzvf nginxconfig.io-xgqfrms.xyz.tar.gz

Let's Encrypt

# Generate Diffie-Hellman keys by running this command on your server:
$ openssl dhparam -out /etc/nginx/dhparam.pem 2048 # Create a common ACME-challenge directory (for Let's Encrypt):
$ mkdir -p /var/www/_letsencrypt
$ chown www-data /var/www/_letsencrypt

# Comment out SSL related directives in the configuration:
$ sed -i -r 's/(listen .*443)/\1;#/g; s/(ssl_(certificate|certificate_key|trusted_certificate) )/#;#\1/g' /etc/nginx/sites-available/xgqfrms.xyz.conf # Reload your NGINX server:
$ sudo nginx -t && sudo systemctl reload nginx # Obtain SSL certificates from Let's Encrypt using Certbot:
$ certbot certonly --webroot -d xgqfrms.xyz --email info@xgqfrms.xyz -w /var/www/_letsencrypt -n --agree-tos --force-renewal # Uncomment SSL related directives in the configuration:
$ sed -i -r 's/#?;#//g' /etc/nginx/sites-available/xgqfrms.xyz.conf # Reload your NGINX server:
$ sudo nginx -t && sudo systemctl reload nginx # Configure Certbot to reload NGINX when it successfully renews certificates:
$ echo -e '#!/bin/bash\nnginx -t && systemctl reload nginx' | sudo tee /etc/letsencrypt/renewal-hooks/post/nginx-reload.sh
$ sudo chmod a+x /etc/letsencrypt/renewal-hooks/post/nginx-reload.sh

Let's go live!

# Reload NGINX to load in your new configuration:
$ sudo nginx -t && sudo systemctl reload nginx

configs

/etc/nginx/nginx.conf

# Generated by nginxconfig.io
# https://www.digitalocean.com/community/tools/nginx?domains.0.server.domain=xgqfrms.xyz&global.https.ocspCloudflareType=both&global.https.ocspGoogleType=both&global.https.ocspOpenDnsType=both user www-data;
pid /run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 65535; 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;
client_max_body_size 16M; # MIME
include mime.types;
default_type application/octet-stream; # Logging
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn; # 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 [2606:4700:4700::1111] [2606:4700:4700::1001] 8.8.8.8 8.8.4.4 [2001:4860:4860::8888] [2001:4860:4860::8844] 208.67.222.222 208.67.220.220 [2620:119:35::35] [2620:119:53::53] valid=60s;
resolver_timeout 2s; # Load configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

/etc/nginx/sites-available/xgqfrms.xyz.conf

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name xgqfrms.xyz;
set $base /var/www/xgqfrms.xyz;
root $base/public; # SSL
ssl_certificate /etc/letsencrypt/live/xgqfrms.xyz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xgqfrms.xyz/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/xgqfrms.xyz/chain.pem; # security
include nginxconfig.io/security.conf; # 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$ {
include nginxconfig.io/php_fastcgi.conf;
}
} # subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name *.xgqfrms.xyz; # SSL
ssl_certificate /etc/letsencrypt/live/xgqfrms.xyz/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xgqfrms.xyz/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/xgqfrms.xyz/chain.pem;
return 301 https://xgqfrms.xyz$request_uri;
} # HTTP redirect
server {
listen 80;
listen [::]:80;
server_name .xgqfrms.xyz;
include nginxconfig.io/letsencrypt.conf; location / {
return 301 https://xgqfrms.xyz$request_uri;
}
}

/etc/nginx/nginxconfig.io/letsencrypt.conf

# ACME-challenge
location ^~ /.well-known/acme-challenge/ {
root /var/www/_letsencrypt;
}

/etc/nginx/nginxconfig.io/security.conf

# security headers
add_header X-Frame-Options "SAMEORIGIN" always;
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: data: blob: 'unsafe-inline'" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; # . files
location ~ /\.(?!well-known) {
deny all;
}

/etc/nginx/nginxconfig.io/general.conf

# favicon.ico
location = /favicon.ico {
log_not_found off;
access_log off;
} # robots.txt
location = /robots.txt {
log_not_found off;
access_log off;
} # assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
access_log off;
} # svg, fonts
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
access_log off;
} # gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;

/etc/nginx/nginxconfig.io/php_fastcgi.conf

# 404
try_files $fastcgi_script_name =404; # default fastcgi_params
include fastcgi_params; # fastcgi settings
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
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/";


refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


NGINX configure auto generator的更多相关文章

  1. URL & QRcode auto generator

    URL & QRcode auto generator 二维码 npm & qrcode https://www.npmjs.com/package/qrcode https://ww ...

  2. Nginx Configure

    1.主配置/etc/nginx.conf #/etc/nginx/nginx.conf user nginx; worker_processes auto; error_log /var/log/ng ...

  3. gitignore auto generator

    gitignore auto generator .gitignore https://gitignore.io/ https://www.toptal.com/developers/gitignor ...

  4. Nginx Configure时配置

    Configure Arguments Configure arguments common for nginx binaries from pre-built packages for stable ...

  5. nginx configure fastdfs + SSL

    ./configure \ --prefix=/usr/local/nginx \ --with-http_stub_status_module \ --with-http_ssl_module \ ...

  6. nginx configure参数

    下面是nginx源码程序的configure参数: --prefix= 指向安装目录.默认为:/usr/local/nginx --sbin-path= 指定执行程序文件存放位置.默认为:prefix ...

  7. nginx configure 错误记录

    1.the HTTP rewrite module requires the PCRE library. ./configure: error: the HTTP rewrite module req ...

  8. 转载:configure执行流程(1.5.2)《深入理解Nginx》(陶辉)

    原文:https://book.2cto.com/201304/19619.html 我们看到configure命令支持非常多的参数,读者可能会好奇它在执行时到底做了哪些事情,本节将通过解析confi ...

  9. centos 7.0 安装nginx 1.9.10

    可以参考以前安装成功的案例 centos 7.0 nginx 1.7.9成功安装过程 官网下载 http://nginx.org/en/download.html nginx下载位置 /usr/loc ...

随机推荐

  1. (04)-Python3之--字典(dict)操作

    1.定义 字典的关键字:dict 字典由多个键和其对应的值构成的 键-值 对组成,每个键值对用冒号 : 分割,每个键值对之间用逗号 , 分割,整个字典包括在花括号 {} 中. {key1:value1 ...

  2. Excel常见后缀名

    1.格式.xlsx:excel2007-2016版默认的文件格式,不能有宏: 2.格式.xls:excel97-2003版,可以有宏: 3.格式.csv:以逗号分隔的文本文件,便于兼容其他程序,只保存 ...

  3. Spring Boot整合Spring Data JPA

    1.JPA 2.Spring Data JPA 3.导入依赖 4.连接数据库 5.实体类 6.Repository 7.测试 1.JPA JPA是Java Persistence API的简称,中文名 ...

  4. spark SQL(三)数据源 Data Source----通用的数据 加载/保存功能

    Spark SQL 的数据源------通用的数据 加载/保存功能 Spark SQL支持通过DataFrame接口在各种数据源上进行操作.DataFrame可以使用关系变换进行操作,也可以用来创建临 ...

  5. unix环境高级编程第三章笔记

    文件描述符 1.文件描述符的概念 对于内核而言,所有打开的文件都会用一个文件描述符来引用,打开或和创建一个新文件的时候,内核会给进程返回一个文件描述符,而当使用read write时,可以使用这个文件 ...

  6. 2019牛客多校 Round2

    Solved:2 Rank:136 A Eddy Walker 题意:T个场景 每个场景是一个长度为n的环 从0开始 每次要么向前走要么向后走 求恰好第一次到m点且其他点都到过的概率 每次的答案是前缀 ...

  7. JavaScript函数console、this关键字

    console.dir()打印出来的东西不加任何操作 console.log()打印出来东西实现进行了操作,打印出来的东西可能不是原型 具体对象的类型可以在"_proto_"中看, ...

  8. Python 装包与拆包

    装包就是把未命名的参数放到元组中,把命名参数放到字典中 a = 1, 2 print(a) (1, 2) 拆包将一个结构中的数据拆分为多个单独变量中 *args **kwargs def run1(* ...

  9. 安装jdk并配置环境变量

    安装jdk并配置环境变量 安装jdk 点击访问官网 https://www.oracle.com/downloads/或直接下载 https://www.jdkdownload.com/ 推荐使用后面 ...

  10. MySQL 回表查询 & 索引覆盖优化

    回表查询 先通过普通索引的值定位聚簇索引值,再通过聚簇索引的值定位行记录数据 建表示例 mysql> create table user( -> id int(10) auto_incre ...