YOURLS:403在mydomain.com上被禁止,在mydomain.com/admin上有502 Bad Gateway

时间:2017-08-11 20:41:18

标签: php mysql nginx ubuntu-16.04 yourls

所以我试图在我的Ubuntu 16.04 DO Droplet上设置YOURLS URL缩短器。我对MySQL和PHP都很陌生,所以我无法弄清楚可能出现的问题。我对Nginx非常满意,因为我一直在使用它,但似乎这些错误是由MySQL数据库和/或PHP配置引起的。

设置: Nginx root(对于网站):/var/www/bnbr.co/public_html (bnbr.co是我将要使用的域名)

PHP config file(位于/var/www/bnbr.co/public_html/config.php

php7.0-fpm pool(位于/etc/php/7.0/fpm/pool.d/username.conf

MySQL设置:

MariaDB [(none)]> CREATE DATABASE yourls; MariaDB [(none)]> GRANT ALL PRIVILEGES ON yourls.* TO 'username'@'localhost' IDENTIFIED BY 'passwd'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> \q

编辑:域的Nginx配置文件(位于/etc/nginx/sites-enabled/bnbr_co

            # main

                    server {

                            listen 443;
                            server_name bnbr.co;

                            root /var/www/bnbr.co/public_html;
                            index index.php;

                            ssl on;
                            ssl_certificate /etc/letsencrypt/live/bnbr.co/cert.pem;
                            ssl_certificate_key /etc/letsencrypt/live/bnbr.co/privkey.pem;

                            ssl_session_timeout 10m;

                            ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
                            ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
                            ssl_prefer_server_ciphers on;

                      location / {

                    try_files $uri $uri/ /yourls-loader.php;
                    expires 14d;
                    add_header Cache-Control 'public';
                }

                location ~ \.php$ {
                    fastcgi_split_path_info ^(.+\.php)(/.+)$;
                    fastcgi_pass unix:/var/run/php/php7.0-fpm-username.sock;
                    fastcgi_index index.php;
                    include fastcgi_params;
                    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                    fastcgi_intercept_errors off;
                    fastcgi_buffer_size 16k;
                    fastcgi_buffers 4 16k;
}
            }





    # HTTP --> HTTPS REDIRS

            # main

                    server {
                            listen 80;
                            server_name bnbr.co;
                            return 301 https://$server_name$request_uri;
                    } #`

我对这些东西很陌生,所以我希望你们能帮忙。

谢谢!

1 个答案:

答案 0 :(得分:0)

我将把所有必要的步骤放在这里。

1)创建用户并完成它会询问的步骤:

adduser bnbr

2)创建文件夹:

mkdir -p /home/bnbr/public
mkdir -p /home/bnbr/logs
mkdir -p /home/bnbr/tmp

3)将您的资料复制到public文件夹

4)设置所有者和mods:

chown -R bnbr:bnbr /home/bnbr
chmod -R 0755 /home/bnbr/public
chmod -R 0755 /home/bnbr/logs
chmod -R 0755 /home/bnbr/tmp

5)在/etc/php/7.0/fpm/pool.d/bnbr.conf创建php pool config,其中包含以下内容:

[brbr]

user = brbr
group = brbr

listen = /var/run/php-fpm.brbr.sock
listen.owner = brbr
listen.group = brbr
listen.mode = 0666

pm = ondemand
pm.max_children = 16
pm.process_idle_timeout = 10s
pm.max_requests = 32
chdir = /

php_admin_flag[display_errors] = on
php_admin_value[error_log] = /home/bnbr/logs/fpm-php.bnbr.log
php_admin_value[log_level] = "warning"
php_admin_flag[log_errors] = on
php_admin_value[memory_limit] = 128M
php_admin_value[post_max_size] = 16M
php_admin_value[upload_max_filesize] = 16M
php_admin_value[upload_tmp_dir] = /home/bnbr/tmp
php_admin_flag[allow_url_fopen] = on
php_admin_value[open_basedir] = "/usr/share/php:/tmp:/usr/local/lib/php:/home/brbr/logs:/home/bnbr/public:/home/bnbr/tmp"

6)重启php-fpm服务

7)为nginx创建主机配置并启用它:

server {
  listen ssl 443;
  server_name bnbr.co www.bnbr.co;

  root /home/bnbr/public
  index index.php;

  ssl on;
  ssl_certificate /etc/letsencrypt/live/bnbr.co/cert.pem;
  ssl_certificate_key /etc/letsencrypt/live/bnbr.co/privkey.pem;
  ssl_session_timeout 10m;
  ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
  ssl_prefer_server_ciphers on;

  location / {
    try_files $uri $uri/ /yourls-loader.php;
    autoindex off;
    access_log off;
    if (!-f $request_filename) {
      rewrite /(.*)$ /yourls-loader.php last;
      break;
    }
  }

  location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm.bnbr.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
  }
}

8)重启nginx



说明:

我正在创建bnbr用户,以便将具有用户权限的所有内容保存在具体位置。

在php-fpm池配置中告诉我需要具有bnbr权限的fpm监听器,并且还定义fpm php进程生成的位置可以使用open_basedir指令访问。

告诉nginx检查/home/bnbr/public文件夹。

P.S。不需要letsencrypt,只需将您的域附加到CloudFlare,它将为您提供长期通配符ssl证书+将隐藏您的服务器免受ddos攻击。