0
点赞
收藏
分享

微信扫一扫

nignx多域名多站点的配置,502 Bad Gateway解决方法

阿尚青子自由写作人 2023-12-21 阅读 49

本文以ubuntu为例,其他Linux系统类似

1、先建立两个放网站的目录

mkdir /data

mkdir /data/ding1com

mkdir /data/ding2com


2、查看nginx.conf可知放入位置sites-enabled文件夹内所有文件都生效

cd /etc/nginx

cp -r sites-enabled sites-enabled.bak #修改前先备份

cd sites-enabled

多域名可在一个文件内设置,也可以拆分多个文件。格式如下:修改root行和server_name行即可

server {
	listen 80;
	root /data/ding1com;
 
	index index.php index.html index.htm index.nginx-debian.html;
 
	server_name localhost ding1.com www.ding1.com;
	
	location ~ \.php$ {
            fastcgi_pass   unix:/run/php/php7.2-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }	
}


3、修改hosts对应域名记录

vim /etc/hosts

127.0.0.1 localhost ding1.com www.ding1.com ding2.com www.ding2.com

4、重启nginx即可

nginx -t //检查错误

sudo /etc/init.d/nginx restart


注意:按照老版本的写法,fastcgi_pass 127.0.0.1:9000; 访问php文件就会报错 502 Bad Gateway,改成上面的写法即可,这个问题困扰了我好几天。

------------------------------------------------------------------------------------------------------------------------

访问php文件,502 Bad Gateway,问题解决记录

/etc/init.d/php7.2-fpm status #正常

netstat -ntlp #查看 发现php-fpm不监听9000端口

cd /etc/php/7.2/fpm 查看php-fpm.conf

查看 /etc/php/7.2/fpm/pool.d/www.conf

找到

listen = /run/php/php7.2-fpm.sock

所以要把nginx配置文件中127.0.0.1:9000 改为 unix:/run/php/php7.2-fpm.sock;


nginx默认网站位置:/usr/share/nginx/html

nginx 错误日志位置:/var/log/nginx/error.log

举报

相关推荐

0 条评论