/ VPS相关 / 14浏览

个人博客nginx反代配置完整

本博客完整的网站nginx反代配置,通过路径/etc/nginx/conf.d/ekhysis.com.conf访问该文件修改。

server {
    listen 80;
    server_name ekhysis.com www.ekhysis.com;

    # 强制重定向到 HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name ekhysis.com www.ekhysis.com;

    # SSL 配置
    ssl_certificate /etc/nginx/ssl/ekhysis.com.fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/ekhysis.com.key.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
    ssl_prefer_server_ciphers on;

    # 网站根目录
    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    # 访问日志
    access_log /var/log/nginx/ekhysis.access.log main;
    error_log /var/log/nginx/ekhysis.error.log;

    # WordPress 主配置
    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # 修复 /wp-admin 问题
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;

    # FastCGI 配置
    location ~ \.php$ {
        fastcgi_pass   unix:/run/php/php7.4-fpm.sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # 错误页面
    error_page   500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
}

其中这个main日志需要在/etc/nginx/nginx.conf主文件中修改。

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;

    include /etc/nginx/conf.d/*.conf;
}
更新于

0

  1. 感谢阅读

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注