php - php 和 nginx 上的虚拟专用服务器配置问题 - ip 有效但域无效
问题描述
我有一个无法正常工作的 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;
}
}
解决方案
必须安装 php-config 然后确保 php.ini 启用了 postgresql 扩展。还必须修复 nginx 站点可用/默认中的服务器块