server {
listen 8080 default_server;
listen [::]:8080 default_server;
server_name cad.domain.tech;
root /var/www/cad;
index index.php;
location ~* \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
我在NGINX网站上有此文件,当我执行IP:8080时,我得到了放置在那里的网页。但是,当我执行cad.domain.tech时,出现“找不到服务器”。
有人有什么想法吗?
这是因为访问http://cad.domain.tech
时,它默认情况下在端口80上请求您的服务器(如果请求以https://
开头,则为端口443)。
因此,您需要做的就是将端口80上的所有传入请求重定向到端口8080。
server {
listen 80;
listen [::]:80;
hostname cad.domain.tech www.cad.domain.tech;
return 301 http://cad.domain.tech:8080
}
这应该有效。 return 301
告诉请求者这是永久重定向。