.pem文件_nginx配置文件不知如何配置?|分享配置文件一键生成器

雪竹运维杂记 2019-11-29 17:00:00

概述
日常工作中,在部署好nginx之后,针对配置文件,大家往往有以下困惑。

  • 需要设置哪些参数?
  • 参数值需要设置成多少?
  • 有特定需求的,参数如何设置?如代理参数?ssl参数等。

下面分享一个配置文件一键生成神器,只要输入域名,选择相关选项,即可生成配置文件。
地址: https://http://nginxconfig.io
NGINX Config 支持 HTTP、HTTPS、PHP、Python、Node.js、WordPress、Drupal、缓存、逆向代理、日志等各种配置选项。在线生成 Web 服务器 Nginx 配置文件。
操作配置也非常简单,你需要做的只需要2步:

  • 打开官方网站
  • 按需求配置相关参数

系统就会自动生成特定的配置文件。生成的Nginx格式非常规范。

b03cadcbbfb1afea6339f8ecee727f99.png

案例展示案例描述

  • 访问http://example.com时,直接跳转到https://example.com,完成http重定向。
  • 访问tomcat目录时,直接跳转到本机的8080端口。

生成的配置展示1、生成主配置文件
cat /etc/nginx/sites-available/example.com.conf
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
root /var/www/http://example.com/var/www/abc.com;
# SSL
ssl_certificate /etc/letsencrypt/live/http://example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/http://example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/http://example.com/chain.pem;
# security
include http://nginxconfig.io/security.conf;
# index.html fallback
location / {
try_files $uri $uri/ /index.html;
}
# reverse proxy
location /tomcat {
proxy_pass http://127.0.0.1:8080;
include http://nginxconfig.io/proxy.conf;
}
# additional config
include http://nginxconfig.io/general.conf;
}
# subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name *.example.com;
# SSL
ssl_certificate /etc/letsencrypt/live/http://example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/http://example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/http://example.com/chain.pem;
return 301 https://example.com$request_uri;
}
# HTTP redirect
server {
listen 80;
listen [::]:80;
server_name .example.com;
include http://nginxconfig.io/letsencrypt.conf;
location / {
return 301 https://example.com$request_uri;
}
}2、反向代理配置
cat /etc/nginx/http://nginxconfig.io/proxy.conf
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;3、其他nginx一般配置及安全配置

a49c66e182dce999da51ac1610c8284c.png

598e2c0e04b1646d0ac606d2a607f363.png

小结
1、通过上面的配置一个基础的nginx模板就生成了,具体的其他需求细节大家可以根据自己项目的实际情况,进行调整。
2、重要的还是要熟悉每个参数代表的意义,这样才能根据实际情况进行有针对性的调整,使用nginx性能达到最优。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值