【发布时间】: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';
网址有效。
任何帮助将不胜感激!
【问题讨论】: