【发布时间】:2020-03-12 04:59:11
【问题描述】:
我已经设置了一台运行 Ubuntu Server 18.0.4 的 Virtual Box 客户机。我正在尝试在本地系统上为在 LEMP 堆栈上运行的 Wordpress 网站设置测试环境。跟着网上的一些文章,搭建了php7.2-fpm和nginx服务器以及mysql社区版。 LEMP 设置似乎很好,因为我已经使用包含 phpinfo 函数的测试文件对其进行了验证。出于测试目的,已在虚拟机来宾上配置了一个虚拟静态 IP 地址。
NGINX 中有两个服务器块 - 默认值,指向 phpinfo 和 knowhow.com,指向预期的 Wordpress 网站。符号链接存在于启用站点的目录中,并且在站点可用目录中设置了knowhow.com 文件。但是,当我尝试使用 /knowhow.com 访问 Wordpress 站点时,我收到 404 Not Found 错误。
进行了一些研究,看来knowhow.com 配置文件中的一些重写规则可能不正确。我不知道什么应该是正确的格式。我想访问我的网站。因此,理想情况下,所有请求都应该转到 index.php。下面提供了knowhow.com 配置文件的内容。有人可以帮忙吗?
# Default server configuration
#
server {
listen 80;
listen [::]:80;
root /var/www/knowhow.com/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name knowhow.com www.knowhow.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# pass PHP scripts to FastCGI server
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
}
【问题讨论】:
-
您的测试 phpinfo 文件在磁盘上的什么位置,您使用什么 URL 访问它?
-
/var/www/html/。我以 static-ip-ipaddress/info.php 的形式访问它
标签: nginx ubuntu-18.04 nginx-location nginx-config php-7.2