nginx 配置及问题

找到 /etc/nginx/nginx.conf 文件,最新版的nginx默认在这个文件中没有 server 的配置了,而是引入了两个文件夹

 

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

我们可以将自定义的域名地址放到 conf.d文件夹中,如新建一个cymanage.cn.conf文件,配置 cymanage.cn 域名

sites-enabled中有一个 default 文件,里面配置了 localhost 信息,我们修改这个文件使其支持 php

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.html index.php index.htm index.nginx-debian.html; // 添加 index.php

	server_name _; // 域名 不需要改动

	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:/run/php/php7.3-fpm.sock; 
		# With php-cgi (or other tcp sockets):
	#	fastcgi_pass 127.0.0.1:9000;
	}

	......
}

 

关于 fastcgi_pass 配置

 

默认配置中有两行 fastcgi_pass 配置,一般开启第二个 127.0.0.1:9000,但是我的开启后报错,/var/log/nginx/error.log

connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: _, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

netstat -ant | grep 9000          发现9000端口并没有被监听

在 php 安装目录下找到 php-fpm.conf,我的在 /etc/php/7.3/fpm/

最后一行 include=/etc/php/7.3/fpm/pool.d/*.conf

打开 pool.d/www.conf 找到 listen

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

修改 fastcgi_pass 配置 unix:/run/php/php7.3-fpm.sock;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值