通知 爱刷机 路由器教程 →→《省钱助手

openwrt安装nginx+php+mysql详细教程owncloud私有云的nginx配置文件

2021-06-11
0评论
/
阅读
爱搜啊

openwrt安装nginx+php+mysql详细教程

opkg update
opkg install php5 php5-mod-gd php5-mod-session php5-mod-pdo php5-mod-pdo-mysql php5-mod-mysql php5-mod-mcrypt php5-mod-mbstring php5-fastcgi php5-cgi php5-mod-xml php5-mod-ctype php5-mod-curl php5-mod-exif php5-mod-ftp php5-mod-iconv php5-mod-json php5-mod-sockets php5-mod-sqlite3 php5-mod-tokenizer php5-mod-zip
opkg install mysql-server 
opkg install nginx spawn-fcgi zoneinfo-core zoneinfo-asia
opkg install shadow-groupadd shadow-useradd
groupadd www
useradd -g www www
chown -R www:www /mnt/sda1/web

修改/etc/my.cnf

datadir                = /mnt/sda1/data/mysql/

tmpdir                = /mnt/sda1/data/tmp/

创建数据库文件夹

mkdir -p /mnt/sda1/data /mnt/sda1/data/mysql /mnt/sda1/data/tmp

创建默认的数据库

/usr/bin/mysql_install_db --force

启动mysql

/etc/init.d/mysqld start

输入如下命令创建mysql的密码

/usr/bin/mysqladmin -u root password 123456

登陆数据库

mysql -u root -p

连接上mysql之后,创建数据库(可以自己定义,记住就行了,之后会用到)

create database abcd
\g

查看当前可用数据库

show databases
\g

退出mysql
quit

修改/etc/nginx/nginx.conf

user www www;
worker_processes  1;
pid        /var/run/nginx.pid;
error_log  /var/log/nginx_error.log;
events {
        use epoll;
        worker_connections  1024;
}
http {
        include mime.types;
        default_type application/octet-stream;
        sendfile on;
        tcp_nopush on;
        #keepalive_timeout 0;
        keepalive_timeout 65;
        gzip on;
        access_log   off;
    
        include       vhost.conf;
}

修改/etc/nginx/fastcgi_params,解决Nginx文件类型错误解析漏洞

if ($request_filename ~* (.*)\.php) {
    set $php_url $1;
}
if (!-e $php_url.php) {
    return 403;
}
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

添加/etc/nginx/vhost.conf

server {
        listen       80;
        server_name  localhost;
        root  /mnt/sda1/web;
        index  index.html index.htm index.php default.php;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        root html;
        }
        location ~* ^.+\.php(\/.*)*$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

修改/etc/php.ini

short_open_tag = on
#doc_root = "/mnt/www" 
extension=ctype.so
extension=curl.so
extension=gd.so
extension=mbstring.so
extension=mcrypt.so
extension=mysql.so
extension=pdo.so
extension=pdo_mysql.so
extension=session.so
extension=sockets.so
extension=tokenizer.so
extension=xml.so
[Date]
date.timezone = Asia/Shanghai
[MySQL]
mysql.default_socket = /var/run/mysqld.sock

启动spawn-fcgi(如需开机自动运行,可将命令添加到/etc/rc.local)

datadir                = /mnt/sda1/data/mysql/

tmpdir                = /mnt/sda1/data/tmp/0

启动nginx

datadir                = /mnt/sda1/data/mysql/

tmpdir                = /mnt/sda1/data/tmp/1

附送一个owncloud私有云的nginx配置文件。

datadir                = /mnt/sda1/data/mysql/

tmpdir                = /mnt/sda1/data/tmp/2

点击链接加入群聊三群:751529538

点击链接加入群聊二群:376877156

点击链接加入群聊【路由器交流群:622891808已满】

本站附件分享,如果附件失效,可以去找找看

诚通网盘附件百度网盘附件


饿了么红包

饿了么红包

于2021-06-11发布