主机+ phpmyadmin =配置

时间:2016-01-02 19:38:48

标签: php nginx

我开始尝试使用nginx。 首先,我想安装phpmyadmin,我认为这是一个很好的练习。

**信息

  • 我的服务器使用ubuntu 14.04
  • 我的服务器只有IPv6
  • 访问phpmyadmin的网址为:phpmyadmin.soapoperator.com

***配置:

公共html文件夹:

root@server01:/usr/share/nginx/html# ls -l
total 12
-rw-r--r-- 1 root root 537 Mar 4 2014 50x.html
-rw-r--r-- 1 root root 612 Mar 4 2014 index.html
-rw-r--r-- 1 root root 20 Jan 1 13:21 info.php
lrwxrwxrwx 1 root root 21 Dec 31 18:41 phpmyadmin -> /usr/share/phpmyadmin

配置可用站点:

root@server01:/etc/nginx/sites-available# ls -l
total 8
-rw-r--r-- 1 root root 833 Jan 1 14:19 phpmyadmin.soapoperator.com
-rw-r--r-- 1 root root 2603 Jan 1 13:35 default

配置主机

server {
listen 80;
#listen [::]:80 ipv6only=on;
server_name phpmyadmin.soapoperator.com;

root /usr/share/nginx/html/phpmyadmin;
index index.php index.html index.htm;

# allow
#allow 82.230.xx.x;
#allow 2a01:e35:2e65:3070:xxx:xxx:c95c:69a;
# drop rest of the world
#deny all;

# Logs
access_log /var/log/phpmyadmin.access_log;
error_log /var/log/phpmyadmin.error_log;

# Default location settings
location / {
charset utf-8;
client_max_body_size 20M;
}

location ~* \.php$ {
# Prevent Zero-day exploit
try_files $uri =404;
# Pass the PHP scripts to FastCGI server
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
fastcgi_param HTTPS off;
}
}

我启用了网站:

root@server01:/etc/nginx/sites-enabled# ls -l
total 0
lrwxrwxrwx 1 root root 46 Jan 1 13:54 phpmyadmin.soapoperator.com -> /etc/nginx/sites-available/phpmyadmin.soapoperator.com
lrwxrwxrwx 1 root root 34 Dec 31 14:28 default -> /etc/nginx/sites-available/default

不幸的是,当我访问phpmyadmin网址时,我到达了nginx欢迎页面。 所以我猜vhost配置不好。但为什么呢?

我想知道这是不是因为ipv6配置问题。 我尝试添加到主机配置:

listen [::]:80 ipv6only=on;

但是我收到了一个错误:

2016/01/02 11:48:45 [emerg] 12636#0: duplicate listen options for [::]:80 in /etc/nginx/sites-enabled/default:22

或者是php问题,因为当我尝试访问http://[my_ip]/info.php时,该文件将作为下载而不是执行。

提前感谢您的帮助。 JB

[[编辑]]

nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        ##
        # nginx-naxsi config
        ##
        # Uncomment it if you installed nginx-naxsi
        ##

        #include /etc/nginx/naxsi_core.rules;

        ##
        # nginx-passenger config
        ##
        # Uncomment it if you installed nginx-passenger
        ##

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

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

        ##
        # Special for 502 error
        ##

        fastcgi_buffers 8 16k;
        fastcgi_buffer_size 32k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;

        ##
        # Access control
        ##

        include blockips.conf;

}

1 个答案:

答案 0 :(得分:1)

最后我通过编辑 /etc/php5/fpm/php.ini 来解决问题,并确保 cgi.fix_pathinfo 设置为0.另一方面,我把 listen = /var/run/php5-fpm.sock 在/etc/php5/fpm/pool.d/www.conf

我不确定哪种修改能真正解决问题。

我的研究: regex demohttp://www.sitepoint.com/setting-up-php-behind-nginx-with-fastcgi/

总而言之,我的vhost就是这样:

server {
        listen 80;
        listen [::]:80;
        server_name phpmyadmin.soapoperator.com;
        server_name_in_redirect off;

        root /usr/share/nginx/html/phpmyadmin;
        index index.php index.html index.htm;

        # allow
        allow   82.230.xx.x;
        allow   2a01:e35:xxxx:xxxx::/xx;
        # drop rest of the world
        deny    all;

        # Logs
        access_log /var/log/phpmyadmin.access_log;
        error_log /var/log/phpmyadmin.error_log;

        # Default location settings
        location / {
                try_files $uri $uri/ /index.php?$args;
                charset utf-8;
                client_max_body_size 20M;
        }

        # Images and static content is treated different
        location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
                access_log        off;
                expires           360d;
        }

        # Deny access to .htaccess files, if Apache's document root
        location ~ /\.ht {
                deny  all;
        }

        location ~ /(libraries|setup/frames|setup/libs) {
                deny all;
                return 404;
        }

        # Pass the PHP scripts to FastCGI server
        location ~* \.php$ {
                # Prevent Zero-day exploit
                try_files $uri =404;
                #
                fastcgi_split_path_info ^(.+?\.php)(/.*)$;
                if (!-f $document_root$fastcgi_script_name) {
                        return 404;
                }
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include /etc/nginx/fastcgi_params;
                fastcgi_param HTTPS off;
        }

        # Redirect server error pages to the static page
        error_page   403  /403.html;
        error_page 404 /404.html;
        error_page   500 502 503 504  /50x.html;

        # Exclude favicon from the logs to avoid bloating when it's not available
        location /favicon.ico {
                log_not_found   off;
                access_log      off;
        }

}