【发布时间】:2021-07-30 11:52:49
【问题描述】:
我的 VPS 设置无法正常工作。
环境:Ubuntu 18.04、php7.4、postgresql 和 nginx
服务器的 IP 地址解析成功并显示默认的“成功”页面。但是,我想用来指向服务器的域不起作用,并且解析为 404。我觉得这是一个简单的修复,但经过一天的搜索我还没有找到它。
感谢您的帮助!
疑难解答:
windows 上的 nslookup 将域名解析为正确的 IP 地址(我可以只用域名 ssh 进入服务器)
在我的浏览器中使用域时仍然找不到该域。这是/etc/nginx/sites-available/temp.domain:
server {
listen 80;
server_name temp.domain;
root /var/www/temp.domain/public_html;
index index.php index.html;
access_log /var/log/nginx/temp.domain.access.log;
error_log /var/log/nginx/temp.domain.error.log;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ \.php {
fastcgi_index index.php;
fastcgi_pass unix:/usr/local/var/run/php-fpm.socket;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
默认配置:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/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 192.169.0.1; #temp ip address
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# 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.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
【问题讨论】:
-
为什么你有两个
server块?此外,server_name 192.169.0.1;看起来不正确,因为 IP 地址不是名称。 -
所以把所有东西都放在一个服务器块中?我屏蔽了 IP 地址。
-
是的,尝试只使用一个服务器块和正确的
server_name。即使通过 IP 访问也将使用此块。