以下是一个基本的 nginx.conf 配置文件,适用于 CentOS 7.6 系统和 nginx 1.23.3 版本。这个配置文件旨在提供一个高性能和安全的 nginx 环境,可以用来运行各种网站和应用程序。

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

events {
    worker_connections 1024;
}

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

    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;

    server_tokens off;

    server {
        listen 80;
        server_name example.com www.example.com;
        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl http2;
        server_name example.com www.example.com;

        ssl_certificate /etc/ssl/certs/example.com.crt;
        ssl_certificate_key /etc/ssl/private/example.com.key;

        ssl_session_timeout 1d;
        ssl_session_cache shared:SSL:50m;
        ssl_session_tickets off;

        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_prefer_server_ciphers off;

        ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;

        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
        add_header X-Content-Type-Options nosniff;
        add_header X-XSS-Protection "1; mode=block";
        add_header X-Frame-Options "SAMEORIGIN";

        root /var/www/html;
        index index.html;

        location / {
            try_files $uri $uri/ =404;
        }
    }
}

这个配置文件做了以下几个事情:

  • 配置了 nginx 运行的用户为 nginx。
  • 配置了 worker_processes 的自动调整和错误日志的位置。
  • 配置了事件模块的 worker_connections 参数。
  • 配置了 MIME 类型和默认类型。
  • 配置了访问日志的格式和位置。
  • 开启了 sendfile、tcp_nopush、tcp_nodelay 和长连接。
  • 关闭了服务器版本的提示。
  • 配置了 HTTP 端口的重定向到 HTTPS 端口。
  • 配置了 HTTPS 端口的 SSL 证书、加密协议和加密套件。
  • 添加了 Strict-Transport-Security、X-Content-Type-Options、X-XSS-Protection 和 X-Frame-Options 的安全头。
  • 配置了根目录和默认文件,并设置了 404 错误页面。
  • 配置了 HTTP 和 HTTPS 的 server 块。

这个 nginx.conf 配置文件是一个基本的模板,可以根据具体需求进行自定义。例如,可以添加更多的 server 块来支持多个网站或应用程序。

centos76 系统nginx-1233 高性能 nginxconf 配置

原文地址: https://www.cveoy.top/t/topic/bd2Q 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录