NGINX服务器阻止已启用,但网站返回404未找到错误



我已经安装了一台运行Ubuntu服务器18.0.4的虚拟盒子访客机。我正试图在本地系统上为在LEMP堆栈上运行的Wordpress网站设置一个测试环境。根据网上的一些文章,建立了php7.2-fpm和nginx服务器以及mysql社区版。LEMP的设置似乎很好,因为我已经用一个包含phpinfo函数的测试文件验证了它。出于测试目的,已在虚拟箱来宾上配置了一个伪静态ip地址。

NGINX-default中有两个服务器块,分别指向phpinfo和knowhow.com,后者指向Wordpress网站。符号链接存在于sites enabled目录中,knowhow.com文件设置在sites available目录中。然而,当我尝试使用/nohow.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;
}
}

我已经解决了这个问题!事实上,这从一开始就不是一个问题。配置文件定义正确。只是访问网站的方式不正确。我试图从本地主机(vm外部)以静态ip地址/nohow.com访问该网站。我本应该以knowhow.com或www.knowhow.com的身份访问该网站。使用ip地址是不正确的,因为服务器块文件(knowhow.com)会自动将web请求重定向到目标服务器上的相应网站根路径。我已经更新了我的/etc/hosts文件,指向knowhow.com和www.knowhow.com的静态IP地址。真傻!

很抱歉造成这么多混乱。我的设置正在按预期工作。干杯

最新更新