代码之家  ›  专栏  ›  技术社区  ›  pawan19

WordPress的Nginx设置:面临301重定向问题

  •  0
  • pawan19  · 技术社区  · 11 月前

    我们计划在wordpress网站上从Apache/Httpd迁移到Nginx。我认为对我来说,挑战只在于添加 .htaccess nginx配置中的代码,但现在每当我启用nginx时,我都会从网站获得301重定向。

    我现在试图保持设置简单,只是为了看到我的主页上线。请在下面找到配置文件。

    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 4096;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        include /etc/nginx/conf.d/*.conf;
    
        server {
            listen       80;
            listen       [::]:80;
            server_name  _;
            root         /var/www/html/;
    
            include /etc/nginx/default.d/*.conf;
    
            error_page 404 /404.html;
            location = /404.html {
            }
            error_page 500 502 503 504 /50x.html;
            location = /50x.html {
            }
        }
    

    我目前已经从AWS ALB设置了SSL重定向。

    它可以访问我的健康检查文件,但不能访问wordpress主网站

    问题:主WordPress网站无法访问,但使用Apache/Httpd时运行良好。错误日志中没有明显的问题。

    配置中缺少什么?任何帮助都将不胜感激!

    1 回复  |  直到 11 月前
        1
  •  1
  •   OldFart    11 月前

    首先,如果.htaccess文件包含任何有用/定制的内容,则应将其完全移植。

    您没有设置任何处理PHP文件的规则,也没有将任何文件设置为nginx配置的索引文件。应该是index.php。。。

    301来自wordpress配置和数据库条目,用于将siteurl硬编码为https

    确保您正在使用当前和正确的域名/url更新数据库中的所有链接,就像您正在迁移一样 https://developer.wordpress.org/advanced-administration/upgrade/migrating/

    update_option行对此非常有用。。