需要搭建一个 PHP 服务器,于是用了 openSUSE+nginx+php-fpm+postgresql
但是遇到了问题,启动不了,提示访问权限错误。请老鸟帮忙看一看
所有的软件包都是官方源 rpm 安装的,不是我自己拿源代码编译的,如果大神想要复现问题,可以直接安装系统的 rpm。实际上我一直认为系统 rpm 安装比手动源代码安装好的多。
openSUSE Tumbleweed 20201229
nginx 1.19.6
php7 7.4.13
这套配置其实跟 openSUSE 15.2 是一样的
nginx.conf 如下
> #user nginx;
> worker_processes 1;
>
> # load_module lib64/nginx/modules/ngx_http_fancyindex_module.so;
> # load_module lib64/nginx/modules/ngx_http_headers_more_filter_module.so;
> # load_module lib64/nginx/modules/ngx_http_image_filter_module.so;
> # load_module lib64/nginx/modules/ngx_http_perl_module.so;
> # load_module lib64/nginx/modules/ngx_http_xslt_filter_module.so;
> # load_module lib64/nginx/modules/ngx_mail_module.so;
> # load_module lib64/nginx/modules/ngx_rtmp_module.so;
> # load_module lib64/nginx/modules/ngx_stream_module.so;
>
> #error_log /var/log/nginx/error.log;
> #error_log /var/log/nginx/error.log notice;
> #error_log /var/log/nginx/error.log info;
>
> #pid /run/nginx.pid;
>
>
> events {
> worker_connections 1024;
> use epoll;
> }
>
>
> http {
> include mime.types;
> default_type application/octet-stream;
>
> #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
> # '$status $body_bytes_sent "$http_referer" '
> # '"$http_user_agent" "$http_x_forwarded_for"';
>
> #access_log /var/log/nginx/access.log main;
>
> sendfile on;
> #tcp_nopush on;
>
> #keepalive_timeout 0;
> keepalive_timeout 65;
>
> #gzip on;
>
> include conf.d/*.conf;
>
> # server {
> # listen 80;
> # server_name localhost;
>
> #charset koi8-r;
>
> #access_log /var/log/nginx/host.access.log main;
>
> # location / {
> # root /srv/www/htdocs/;
> # index index.html index.htm;
> # }
>
> #error_page 404 /404.html;
>
> # redirect server error pages to the static page /50x.html
> #
> # error_page 500 502 503 504 /50x.html;
> # location = /50x.html {
> # root /srv/www/htdocs/;
> # }
>
> # proxy the PHP scripts to Apache listening on 127.0.0.1:80
> #
> #location ~ \.php$ {
> # proxy_pass http://127.0.0.1;
> #}
>
> # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
> #
> #location ~ \.php$ {
> # root /srv/www/htdocs/;
> # fastcgi_pass 127.0.0.1:9000;
> # fastcgi_index index.php;
> # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
> # include fastcgi_params;
> #}
>
> # deny access to .htaccess files, if Apache's document root
> # concurs with nginx's one
> #
> #location ~ /\.ht {
> # deny all;
> #}
> # }
>
>
> # another virtual host using mix of IP-, name-, and port-based configuration
> #
> #server {
> # listen 8000;
> # listen somename:8080;
> # server_name somename alias another.alias;
>
> # location / {
> # root /srv/www/htdocs/;
> # index index.html index.htm;
> # }
> #}
>
>
> # HTTPS server
> #
> #server {
> # listen 443 ssl;
> # server_name localhost;
>
> # ssl_certificate cert.pem;
> # ssl_certificate_key cert.key;
>
> # Allow TLS version 1.2 only, which is a recommended default these days
> # by international information security standards.
> # ssl_protocols TLSv1.2;
>
> # ssl_session_cache shared:SSL:1m;
> # ssl_session_timeout 5m;
>
> # ssl_ciphers HIGH:! aNULL:! MD5;
> # ssl_prefer_server_ciphers on;
>
> # location / {
> # root /srv/www/htdocs/;
> # index index.html index.htm;
> # }
> #}
>
> include vhosts.d/*.conf;
>
> }
vhosts.d/example.com.conf 如下
server {
listen 80;
server_name example.com;
root /home/developer/mysite/public; # 前端的内容放在这个目录,记得调整目录权限,让运行 nginx 的用户有权访问,简单粗暴可以用 777
index index.html;
location / {
#root /home/developer/mysite/public/;
index index.html index.htm index.php;
}#php-fpm configuration location ~ \.php$ { fastcgi_pass 127.0.0.1:9000;# 如果是 sock 连接则 fastcgi_pass unix:/dev/shm/php-cgi.sock; fastcgi_index index.php; #fastcgi_param APPLICATION_ENV production; include fastcgi.conf; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;# 没有这行就会显示空白页面 }# 和 php-fpm 通信 #css|js|ico|gif|jpg|jpeg|png|txt|html|htm|xml|swf|wav 这些都是静态文件,但应分辨,js、css 可能经常会变,过期时间应小一些,图片、html 基本不变,过期时间可以设长一些 location ~* ^.+\.(ico|gif|jpg|jpeg|png|html|htm)$ { #root /home/developer/mysite/static/; access_log off; expires 30d; } location ~* ^.+\.(css|js|txt|xml|swf|wav)$ { #root /home/developer/mysite/static/; access_log off; expires 24h; }
}
/etc/php7/fpm/php-fpm.conf 和/etc/php7/fpm/php-fpm.d/www.conf 都是用的系统 rpm 安装的默认值
systemctl start php-fpm
systemctl start nginx
都能正常运行
但是当我用浏览器访问 http://localhost/phpinfo.php 时页面却显示 Access Denied
/var/log/nginx/error.log
的记录显示
2021/01/01 10:07:00 [error] 22887#22887: *1 FastCGI sent in stderr: “Unable to open primary script: /home/developer/mysite/public/phpinfo.php (Permission denied)” while reading response header from upstream, client: 127.0.0.1, server: example.com, request: “GET /phpinfo.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “localhost”
但是我把 phpinfo.php 文件的权限设定为 777 也不行
我去查了一下,stackoverflow 上说这个问题大概率是 selinux 引起的,可是只有红帽系的发行版才用 selinux,openSUSE 上根本没有这个 selinux 啊。
请各位老鸟帮我看看到底什么情况,谢谢大家帮忙。