- 问题描述
- 问题分析
- 解决问题
- 附录
在/etc/nginx/sites-available/default 中配置好了后访问域名,要么报502错误,要么访问文件就会下载。
问题分析我的nginx目录是/etc/nginx/
nginx的主配置文件是/etc/nginx/nginx.conf
查看主配置文件,找到error log的位置:
error_log /var/log/nginx/error.log;
查看error.log发现报错:
2022/05/02 12:24:33 [crit] 8526#8526: *6 connect() to unix:/var/run/php/php7.0-fpm.sock failed (2: No such file or directory) while connecting to upstream, client: 183.209.108.63, server: 1 01.132.237.235, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "www.yuanzhe.xyz"
意思是方收到请求index.php的时候找不到php7.0-fpm.sock文件
解决问题经仔细核对发现我的fpm版本是7.2
在配置文件/etc/nginx/sites-available/default中修改fpm版本为7.2后,重启nginx(/etc/init.d/nginx restart),就可以通过域名访问了
下面附上我的配置文件 /etc/nginx/sites-available/default
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html/yuanzhe.xyz;
# Add index.php to the list if you are using PHP
index index.html index.php index.htm index.nginx-debian.html;
server_name 101.132.237.235;
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.2-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;
#}
}



