V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
1024MB
V2EX  ›  程序员

请教一个 nginx+ PHP 本地搭建 wordpress,使用 frp 内网穿透,并通过 nginx 反向代理问题?

  •  
  •   1024MB · 32 天前 · 934 次点击
    这是一个创建于 32 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我在本地使用 nignx 和 php 部署了 wordpress ,本地 nginx 配置的域名是 127.0.0.1:6464,我使用 frp 的 tcp 内网穿透本地 127.0.0.1:6464 到公网的服务器的 6464 端口,然后我在公网服务器也部署了 nginx ,并使用 nginx 反代了 127.0.0.1:6464 端口,并且开启了 ssl ,最后我能访问我的网站,但是样式错误,我 f12 到有 http 的链接,非 https 。我 google 搜索问题,在 wp-config.php 配置了如下信息:

    define('WP_HOME', 'https://www.example.cn');
    define('WP_SITEURL', 'https://www.example.cn');
    

    前端访问正常了,但是我的无法登录到我的 wordprss 后台,也就是https://www.example.cn/wp-login.php,显示重定向次数果过多~~

    我的配置如下:

    公网的 nginx:

    server {
        listen 80 ; 
        server_name www.example.cn; 
        return 301 https://$host$request_uri; # 强制跳转到 HTTPS
    }
    server {
        listen 443 ssl http2 ; 
        server_name www.example.cn; 
        index index.php index.html index.htm default.php default.htm default.html; 
        # SSL 证书配置
        ssl_certificate /www/sites/www.example.cn/ssl/fullchain.pem; 
        ssl_certificate_key /www/sites/www.example.cn/ssl/privkey.pem; 
        ssl_protocols TLSv1.3 TLSv1.2 TLSv1.1 TLSv1; 
        ssl_ciphers ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED; 
        ssl_prefer_server_ciphers on; 
        ssl_session_cache shared:SSL:10m; 
        ssl_session_timeout 10m; 
        # 日志配置
        access_log /www/sites/www.example.cn/log/access.log main; 
        error_log /www/sites/www.example.cn/log/error.log; 
        # 反向代理到内网 Nginx
        location / {
            proxy_pass http://127.0.0.1:6464; # 内网 Nginx 地址
            proxy_set_header Host $host; 
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
            proxy_set_header X-Forwarded-Proto $scheme; 
            proxy_set_header X-Real-IP $remote_addr; 
            proxy_http_version 1.1; 
            proxy_set_header Upgrade $http_upgrade; 
            proxy_set_header Connection "upgrade"; 
        }
        # Let's Encrypt 证书验证
        location ^~ /.well-known/acme-challenge {
            allow all; 
            root /usr/share/nginx/html; 
        }
        # 自定义错误页面
        error_page 497 https://$host$request_uri; # 处理 HTTP 请求到 HTTPS 的重定向
        error_page 404 /404.html; 
        # 添加 HSTS 头
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"; 
    }
    

    内网 Nginx 配置如下:

    server {
        listen 6464;
        server_name _;
        index index.php index.html index.htm default.php default.htm default.html;
        access_log /www/sites/www.example.cn/log/access.log main;
        error_log /www/sites/www.example.cn/log/error.log;
    
        # 网站根目录
        root /www/sites/www.example.cn/index;
    
        # 处理所有请求
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        # 处理 PHP 请求
        location ~ [^/]\.php(/|$) {
            fastcgi_pass 127.0.0.1:9000; # PHP-FPM 监听地址
            include fastcgi-php.conf;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        }
    
        # Let's Encrypt 证书验证
        location ^~ /.well-known/acme-challenge {
            allow all;
            root /usr/share/nginx/html;
        }
    
        # 自定义 404 页面
        error_page 404 /404.html;
    }
    
    

    我的配置哪里出问题了?或者我应该如何进行排查呢?想不明白了,求大佬们解惑。~~~

    1 条回复
    1024MB
        1
    1024MB  
    OP
       32 天前
    自问自己答:添加:$_SERVER['HTTPS'] ='on';
    define('FORCE_SSL_LOGIN', true);
    define('FORCE_SSL_ADMIN', true);
    成功解决
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5385 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 01:33 · PVG 09:33 · LAX 18:33 · JFK 21:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.