【问题标题】:Root URL appended to domain on NGINX and WordPress在 NGINX 和 WordPress 上附加到域的根 URL
【发布时间】:2020-04-15 14:19:50
【问题描述】:

总的来说,我对 NGINX 和 Web 服务器还是很陌生。

我一直在尝试在 NGINX 上安装 WordPress,并且在搜索域时遇到了我的根目录附加到我的域的问题。我相信这与为该域配置 NGINX 的方式有关。这是我用于配置的代码:

# Upstream to abstract backend connection(s) for php
upstream php {
        server unix:/var/run/php/php7.3-fpm.sock;
        server 127.0.0.1:9000;
}

server {
        ## Your website name goes here.
        server_name www.example.com example.com;
        ## Your only path reference.
        root /var/www/example.com;
        ## This should be in your http block and if it is, it's not needed here.
        index index.php;

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

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

        location / {
                # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi_params;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
                #The following parameter can be also included in fastcgi_params file
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
}

这导致我输出的 URL 为:

http://www.example.com/var/www/example.com/wp-admin/setup-config.php

还有一点需要注意。当我编辑wp-load.php 并更改时:

$path = wp_guess_url() . '/wp-admin/setup-config.php';

到:

$path = '/wp-admin/setup-config.php';

网址有效。

任何帮助将不胜感激!

【问题讨论】:

    标签: php wordpress nginx


    【解决方案1】:

    将此保存为配置

    {
        "listeners": {
            "127.0.0.1:8090": {
                "application": "script_index_php"
            },
            "127.0.0.1:8091": {
                "application": "direct_php"
            }
        },
    
        "applications": {
            "script_index_php": {
                "type": "php",
                "processes": {
                    "max": 20,
                    "spare": 5
                },
                "user": "www-data",
                "group": "www-data",
                "root": "/var/www/html/example.com",
                "script": "index.php"
            },
            "direct_php": {
                "type": "php",
                "processes": {
                    "max": 5,
                    "spare": 0
                },
                "user": "www-data",
                "group": "www-data",
                "root": "/var/www/html/example.com",
                "index": "index.php"
            }
        }
    }
    

    此配置创建两个 NGINX 单元应用程序,每个 URL 方案一个 - Web 应用程序和管理面板。

    使用 NGINX Unit 脚本参数而不是 index 参数意味着对未找到页面的请求使用 WordPress 中的主 index.php 脚本。有关更多信息,请参阅 PHP 应用程序对象的 NGINX 单元文档。

    要扩展您的应用程序,请相应地更改 IP 地址和端口。

    运行此 curl 命令以加载配置:

    $ curl -X PUT --data-binary @/var/www/wordpress/wordpress.config --unix-socket /run/control.unit.sock http://localhost/config
    
    ``````
    
    
    
    ````
    

    【讨论】:

      猜你喜欢
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 2012-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-31
      相关资源
      最近更新 更多