Centos 8.0中Nginx配置文件和https正书添加配置

简介: 这是一份Nginx配置文件,包含HTTP与HTTPS服务设置。主要功能如下:1) 将HTTP(80端口)请求重定向至HTTPS(443端口),增强安全性;2) 配置SSL证书,支持TLSv1.1至TLSv1.3协议;3) 使用uWSGI与后端应用通信(如Django);4) 静态文件托管路径设为`/root/code/static/`;5) 定制错误页面(404、50x)。适用于Web应用部署场景。
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
   
    worker_connections 1024;
}

http {
   
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    server {
   
        #HTTPS的默认访问端口443。
        #如果未在此处配置HTTPS的默认访问端口,可能会造成Nginx无法启动。
        listen 443 ssl;

        #填写证书绑定的域名。多域名配置示例:server_name example.com www.example.com doc.example.com;
        server_name www.kij.online;

        #填写证书文件绝对路径
        ssl_certificate /etc/pki/nginx/cert/kij.online.pem;
        #填写证书私钥文件绝对路径
        ssl_certificate_key /etc/pki/nginx/cert/kij.online.key;

        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 5m;

        #自定义设置使用的TLS协议的类型以及加密套件(以下为配置示例,请您自行评估是否需要配置)
        #TLS协议版本越高,HTTPS通信的安全性越高,但是相较于低版本TLS协议,高版本TLS协议对浏览器的兼容性较差。
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;

        #表示优先使用服务端加密套件。默认开启
        ssl_prefer_server_ciphers on;


        location / {
   
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:8000;#端口要和uwsgi里配置的一样
        }
    }
    server {
   
        listen       80 default_server;
        #listen       [::]:80 default_server;
        server_name  www.kij.online;
        #root         /root/code/mysite;

        # Load configuration files for the default server block.
        #include /etc/nginx/default.d/*.conf;

        #将所有HTTP请求通过rewrite指令重定向到HTTPS。
        rewrite ^(.*)$ https://$host$1;

        location / {
   
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:8000;#端口要和uwsgi里配置的一样
        }

        error_page 404 /404.html;
            location = /40x.html {
   
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
   
        }

        location /static/ {
   
            alias /root/code/static/;
        }

    }

# Settings for a TLS enabled server.
#
#    server {
   
#        listen       443 ssl http2 default_server;
#        listen       [::]:443 ssl http2 default_server;
#        server_name  _;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_ciphers PROFILE=SYSTEM;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
   
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
   
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
   
#        }
#    }

}
目录
相关文章
|
5月前
|
人工智能 Ubuntu 前端开发
Dify部署全栈指南:AI从Ubuntu配置到HTTPS自动化的10倍秘籍
本文档介绍如何部署Dify后端服务及前端界面,涵盖系统环境要求、依赖安装、代码拉取、环境变量配置、服务启动、数据库管理及常见问题解决方案,适用于开发与生产环境部署。
1234 1
|
4月前
|
网络安全 开发工具 git
在GitLab CI中同步HTTPS仓库地址的yaml配置
最后,提交并推送 `.gitlab-ci.yml`文件到您的GitLab仓库。GitLab CI/CD将自动识别这个文件,并在每次推送到 `master`分支时执行定义的同步任务。
240 16
|
9月前
|
应用服务中间件 Linux 网络安全
技术指南:如何把docsify项目部署到基于CentOS系统的Nginx中。
总结 与其他部署方法相比,将docsify项目部署到基于CentOS系统的Nginx中比较简单。以上步骤应当帮助你在不花费太多时间的情况下,将你的项目顺利部署到Nginx中。迈出第一步,开始部署你的docsify项目吧!
395 14
|
应用服务中间件 Linux 网络安全
nginx安装部署ssl证书,同时支持http与https方式访问
为了使HTTP服务支持HTTPS访问,需生成并安装SSL证书,并确保Nginx支持SSL模块。首先,在`/usr/local/nginx`目录下生成RSA密钥、证书申请文件及自签名证书。接着,确认Nginx已安装SSL模块,若未安装则重新编译Nginx加入该模块。最后,编辑`nginx.conf`配置文件,启用并配置HTTPS服务器部分,指定证书路径和监听端口(如20000),保存后重启Nginx完成部署。
4584 8
|
负载均衡 Ubuntu 应用服务中间件
nginx修改网站默认根目录及发布(linux、centos、ubuntu)openEuler软件源repo站点
通过合理配置 Nginx,我们可以高效地管理和发布软件源,为用户提供稳定可靠的服务。
1606 13
|
负载均衡 应用服务中间件 Linux
nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件,很全
这篇博客文章详细介绍了Nginx的下载、安装、配置以及使用,包括正向代理、反向代理、负载均衡、动静分离等高级功能,并通过具体实例讲解了如何进行配置。
648 5
nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件,很全
|
负载均衡 NoSQL 应用服务中间件
Nginx编译安装及配置文件详解
Nginx编译安装及配置文件详解
|
负载均衡 关系型数据库 MySQL
Nginx的安装与配置文件结构| 学习笔记
快速学习Nginx的安装与配置文件结构。
Nginx的安装与配置文件结构| 学习笔记
|
负载均衡 关系型数据库 MySQL
Nginx的安装与配置文件结构
一、LNMP架构的部署注意事项 二、Nginx的安装与配置文件结构 三、Nginx常用功能实战
Nginx的安装与配置文件结构
|
Web App开发 缓存 应用服务中间件