Ubuntu上的WordPress-未找到home.php的文件-正在尝试重定向到根文件夹

时间:2020-12-24 作者:user3762448

我最近在通过Vultr安装的Ubuntu服务器上进行了一键安装。有一个PHP URL路径(site.com/home.PHP),我想301重定向到根文件夹(site.com/)中,但到目前为止还没有任何效果。以下是我尝试过的一些事情。。。

设置带有mod rewrite规则的htaccess文件(似乎忽略了这一点)查看了nginx配置文件。我有三个。驾驶舱confwordpress\\u http。confwordpress\\u https。confI尝试了基于其他线程更新一些内容,但没有任何效果(我是服务器配置的初学者,所以我可能也做了错误的事情)。每个配置文件的内容是:

驾驶舱形态

server {
    listen 9080 ssl;
    server_name _;
    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;
    # set max upload size
    client_max_body_size 2G;
    fastcgi_buffers 64 4K;
    access_log /var/log/nginx/cockpit_access.log combined;
    error_log /var/log/nginx/cockpit_error.log;
    server_tokens off;
    location / {
        # Required to proxy the connection to Cockpit
        proxy_pass https://127.0.0.1:9090;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        # Required for web sockets to function
        proxy_http_version 1.1;
        proxy_buffering off;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        # Pass ETag header from Cockpit to clients.
        # See: https://github.com/cockpit-project/cockpit/issues/5239
        gzip off;
    }
}
wordpress\\u http。形态

upstream php-handler-http {
server 127.0.0.1:9000;
}
server {
listen 80 default_server;
server_name _;
#server_name wordpress.example.com;

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

# set max upload size
client_max_body_size 2G;
fastcgi_buffers 64 4K;

access_log /var/log/nginx/wordpress_http_access.log combined;
error_log /var/log/nginx/wordpress_http_error.log;

server_tokens off;

location = /favicon.ico {
log_not_found off;
access_log off;
}

location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}

location / {
try_files $uri $uri/ /index.php?$args ;
}

# protected area (XHProf)
location ^~ /xhprof/xhprof_html/ {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd/xhprof;

location ~ \\.php(?:$|/) {
fastcgi_split_path_info ^(.+\\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_FLAG "session.auto_start=off \\n mbstring.encoding_translation=off";
fastcgi_param PHP_VALUE "assert.active=0 \\n mbstring.http_input=pass \\n mbstring.http_output=pass";
fastcgi_pass php-handler-http ;
fastcgi_read_timeout 60s;
}
}

# protected area (phpmyadmin)
location ^~ /mysqladmin/ {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd/phpmyadmin;

location ~ \\.php(?:$|/) {
fastcgi_split_path_info ^(.+\\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_FLAG "session.auto_start=off \\n mbstring.encoding_translation=off";
fastcgi_param PHP_VALUE "assert.active=0 \\n mbstring.http_input=pass \\n mbstring.http_output=pass";
fastcgi_pass php-handler-http ;
fastcgi_read_timeout 60s;
}
}

location ^~ /wp-admin/install.php {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd/wpadmin;

location ~* \\.(htaccess|htpasswd) {
deny all;
}

location ~ \\.php(?:$|/) {
fastcgi_split_path_info ^(.+\\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
fastcgi_pass php-handler-http;
fastcgi_read_timeout 60s;
}
}

location ~* \\.(htaccess|htpasswd) {
deny all;
}

location ~* \\.(?:ini|conf|txt)$ {
deny all;
}

location ~ \\.php(?:$|/) {
fastcgi_split_path_info ^(.+\\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
fastcgi_pass php-handler-http;
fastcgi_read_timeout 60s;
}

# set long EXPIRES header on static assets
location ~* \\.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
expires 30d;
access_log off;
}

}

wordpress\\u https。形态

upstream php-handler-https {
    server 127.0.0.1:9000;
}

server {
    listen 443 ssl default_server;
    server_name _;
    #server_name wordpress.example.com;

    ssl_certificate /etc/nginx/ssl/server.crt;
    ssl_certificate_key /etc/nginx/ssl/server.key;

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

    # set max upload size
    client_max_body_size 2G;
    fastcgi_buffers 64 4K;

    access_log /var/log/nginx/wordpress_https_access.log combined;
    error_log /var/log/nginx/wordpress_https_error.log;

    server_tokens off;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args ;
    }

    # protected area (XHProf)
    location ^~ /xhprof/xhprof_html/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/xhprof;

        location ~ \\.php(?:$|/) {
          fastcgi_split_path_info ^(.+\\.php)(/.+)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param PHP_FLAG "session.auto_start=off \\n mbstring.encoding_translation=off";
          fastcgi_param PHP_VALUE "assert.active=0 \\n mbstring.http_input=pass \\n mbstring.http_output=pass";
          fastcgi_pass php-handler-http ;
          fastcgi_read_timeout 60s;
        }
    }

    # protected area (phpmyadmin)
    location ^~ /mysqladmin/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/phpmyadmin;

        location ~ \\.php(?:$|/) {
          fastcgi_split_path_info ^(.+\\.php)(/.+)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param PHP_FLAG "session.auto_start=off \\n mbstring.encoding_translation=off";
          fastcgi_param PHP_VALUE "assert.active=0 \\n mbstring.http_input=pass \\n mbstring.http_output=pass";
          fastcgi_pass php-handler-http ;
          fastcgi_read_timeout 60s;
        }
    }

    location ^~ /wp-admin/install.php {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/wpadmin;

        location ~* \\.(htaccess|htpasswd) {
            deny all;
        }

        location ~ \\.php(?:$|/) {
            fastcgi_split_path_info ^(.+\\.php)(/.+)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param HTTPS on;
            fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
            fastcgi_pass php-handler-https;
            fastcgi_read_timeout 60s;
        }
    }

    location ~* \\.(htaccess|htpasswd) {
        deny all;
    }

    location ~* \\.(?:ini|conf|txt)$ {
        deny all;
    }

    location ~ \\.php(?:$|/) {
        fastcgi_split_path_info ^(.+\\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
        fastcgi_pass php-handler-https;
        fastcgi_read_timeout 60s;
    }

    # set long EXPIRES header on static assets
    location ~* \\.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
        expires 30d;
        access_log off;
    }

}


server {
    listen 443 ssl ;
    server_name www.gardenfreshsalsa.com gardenfreshsalsa.com; # managed by Certbot
    #server_name wordpress.example.com;
    ssl_certificate /etc/letsencrypt/live/gardenfreshsalsa.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/gardenfreshsalsa.com/privkey.pem; # managed by Certbot

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

    # set max upload size
    client_max_body_size 2G;
    fastcgi_buffers 64 4K;

    access_log /var/log/nginx/wordpress_https_access.log combined;
    error_log /var/log/nginx/wordpress_https_error.log;

    server_tokens off;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location / {
        try_files $uri $uri/ /index.php?$args ;
    }

    # protected area (XHProf)
    location ^~ /xhprof/xhprof_html/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/xhprof;

        location ~ \\.php(?:$|/) {
          fastcgi_split_path_info ^(.+\\.php)(/.+)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param PHP_FLAG "session.auto_start=off \\n mbstring.encoding_translation=off";
          fastcgi_param PHP_VALUE "assert.active=0 \\n mbstring.http_input=pass \\n mbstring.http_output=pass";
          fastcgi_pass php-handler-http ;
          fastcgi_read_timeout 60s;
        }
    }

    # protected area (phpmyadmin)
    location ^~ /mysqladmin/ {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/phpmyadmin;

        location ~ \\.php(?:$|/) {
          fastcgi_split_path_info ^(.+\\.php)(/.+)$;
          include fastcgi_params;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          fastcgi_param PATH_INFO $fastcgi_path_info;
          fastcgi_param PHP_FLAG "session.auto_start=off \\n mbstring.encoding_translation=off";
          fastcgi_param PHP_VALUE "assert.active=0 \\n mbstring.http_input=pass \\n mbstring.http_output=pass";
          fastcgi_pass php-handler-http ;
          fastcgi_read_timeout 60s;
        }
    }

    location ^~ /wp-admin/install.php {
        auth_basic "Restricted";
        auth_basic_user_file /etc/nginx/htpasswd/wpadmin;

        location ~* \\.(htaccess|htpasswd) {
            deny all;
        }

        location ~ \\.php(?:$|/) {
            fastcgi_split_path_info ^(.+\\.php)(/.+)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_param HTTPS on;
            fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
            fastcgi_pass php-handler-https;
            fastcgi_read_timeout 60s;
        }
    }

    location ~* \\.(htaccess|htpasswd) {
        deny all;
    }

    location ~* \\.(?:ini|conf|txt)$ {
        deny all;
    }

    location ~ \\.php(?:$|/) {
        fastcgi_split_path_info ^(.+\\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param HTTPS on;
        fastcgi_param PHP_VALUE "auto_prepend_file=/var/www/html/xhprof/external/header.php";
        fastcgi_pass php-handler-https;
        fastcgi_read_timeout 60s;
    }

    # set long EXPIRES header on static assets
    location ~* \\.(?:jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {
        expires 30d;
        access_log off;
    }
}
有人能给我指出正确的方向吗?

期望的结果

https://www.abcde.org/home.php -&燃气轮机;301重定向https://www.abcde.org/

1 个回复
SO网友:Rup

我不太了解nginx但你可能只是想

location = /home.php {
  return 301 /;
}
我会把这个放在两个http中。conf和\\u https。之后的conf文件location = /robots.txt { ... } 块你可能想要

location = /home.php {
  return 301 https://$server_name/;
}
在http中。conf版本也包含一个重定向到HTTPS。

相关推荐

Html注释导致函数出现问题。php脚本根目录

我注意到HTML注释标记<!-- --> 将导致主题功能出现问题。php脚本,如果它位于脚本的根目录中(不在函数中)我正在处理主题功能。php添加了一些简单的数字下载操作/过滤器,我意识到购买按钮将继续加载,不会将产品添加到购物篮中清除脚本根目录中的html注释后,问题得到解决。我需要知道在函数中使用HTML注释有什么问题。php根目录?(顺便说一句,我的wp站点托管在cpanel共享主机上)