首页 文章

使phpMyAdmin在Nginx PHP-FPM中作为别名工作

提问于
浏览
0

系统是Fedora 25,Nginx 1.10.2和PHP 7.0.14在CGI模式下工作 .

我使用dnf安装phpMyAdmin,位置是 /usr/share/phpMyAdmin ,所以我尝试让它在多网站中作为别名工作 .

location /phpmyadmin {
    alias /usr/share/phpMyAdmin;
    include fastcgi_php.conf;
}

然后我将位置添加到open_basedir中 .

fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/usr/share/phpMyAdmin/:/var/lib/phpMyAdmin/:/etc/phpMyAdmin/:/usr/share/php:/usr/bin/pear:/dev/null:/var/lib/php";

我打开URL,日志显示此消息:

2016/12/19 17:52:05 [error] 2241#0: *2 FastCGI sent in stderr: "Unable to open primary script: /usr/share/phpMyAdmin/phpmyadmin/index.php (No such file or directory)" while reading response header from upstream, client: 1.1.1.1, server:1.1.1.1 , request: "GET /phpmyadmin/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:"

如何使其正确和有效?谢谢!

更新:

我想也许是因为 fastcgi_param ,为了解决PHP fastcgi中的空白页问题,我在这个文件中加了2行 .

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_script_name;

nginx.conf:

user nginx nginx;
worker_processes 2;
pid /run/nginx.pid;

include /etc/nginx/modules-enabled/*.conf;

events {
    use epoll;
    worker_connections 2048;
    multi_accept on;
}

http {
    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;
    error_log /var/log/nginx/error.log;
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    geoip_country /usr/share/GeoIP/GeoIP.dat;

    charset UTF-8;
    sendfile on;
    send_timeout 10;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 30;
    server_tokens off;
    client_header_timeout 10;
    client_max_body_size 64M;
    client_body_timeout 10;
    client_body_buffer_size 256k;
    open_file_cache max=102400 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 5;
    open_file_cache_errors off;
    types_hash_max_size 4096;
    reset_timedout_connection on;
    fastcgi_buffers 16 32k;
    fastcgi_buffer_size 32k;
    fastcgi_intercept_errors on;
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_min_length 1024;
    gzip_comp_level 6;
    gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

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

fastcgi_php.conf:

location ~ \.php$ {
    fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

website.conf:

server {
listen 443 ssl;
server_name test.domain.com;
root /var/www/site1;
index index.html index.php;
access_log /var/log/site1-access.log combined;
error_log /var/log/site1-error.log warn;
ssl_certificate /etc/nginx/ssl/xxx.crt;
ssl_certificate_key /etc/nginx/ssl/xxx.key;
ssl_dhparam /etc/nginx/ssl/dhparams.pem;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security "max-age=31536000";
add_header X-Content-Type-Options nosniff;

location / {
    try_files $uri $uri/ /error.html;
    include fastcgi_php.conf;
}

location /phpmyadmin {
    alias /usr/share/phpMyAdmin;
    include fastcgi_php.conf;
}

location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
}

location ~ /\. {
    deny all;
}

}

1 回答

  • 0

    它会工作,但没有这样的文件或目录 . Nginx can't find the index.php in /usr/share/phpMyAdmin/phpmyadmin/ 因为该文件夹不存在 .

    您必须编辑phpmyadmin位置的别名路径(请参阅代码片段我是如何做的) . 之后转到/ usr / share / path并将文件夹phpMyAdmin重命名为phpmyadmin(小写)或在Location中使用相同的表示法(例如Location / phpMyAdmin)

    server {
       listen 443 ssl;
       server_name test.domain.com;
       root /var/www/site1;
       index index.html index.php;
    
       # Configure Access and Error Logging
       access_log /var/log/site1-access.log combined;
       error_log /var/log/site1-error.log warn;
    
       # Configure SSL Certification usage
       ssl_certificate /etc/nginx/ssl/xxx.crt;
       ssl_certificate_key /etc/nginx/ssl/xxx.key;
       ssl_dhparam /etc/nginx/ssl/dhparams.pem;
       ssl_session_cache shared:SSL:10m;
       ssl_session_timeout 10m;
       ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
       ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
       ssl_prefer_server_ciphers on;
    
       # Add Headers for security purposes
       add_header Strict-Transport-Security "max-age=31536000";
       add_header X-Content-Type-Options nosniff;
    
       # Define some page rules
       location / {
           try_files $uri $uri/ /error.html;
           include fastcgi_php.conf;
       }
    
       location /phpmyadmin {
           alias /usr/share;
           include fastcgi_php.conf;
       }
    
       location = /robots.txt {
           allow all;
           log_not_found off;
           access_log off;
       }
    
       location ~ /\. {
           deny all;
       }
    

相关问题