There is a module in nginx that has this function. (Extensions in previous articles are called modules here, and will be called modules in the future. The module may be more accurate, because the extension is a separate file, and the module is embedded in the main file) , this module is called drizzle-nginx-module
It’s not easy to compile this
Download the drizzle library first
Compilation and configuration options:
Copy code The code is as follows:
./configure --without-server
make libdrizzle-1.0
make install-libdrizzle-1.0
The next step is the output, http directly outputs the json string , what should I do? I need to download another module. There are too many modules to download.
https://github.com/openresty/rds-json-nginx-module
The final configuration options are as follows:
Copy code The code is as follows:
./configure --prefix=/opt/nginxrw --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --add- module=/data/src/lua-nginx-module-0.9.8 --add-module=/data/src/ngx_devel_kit-0.2.19 --add-module=/data/src/drizzle-nginx-module-0.1 .7 --add-module=/data/src/rds-json-nginx-module-master
When nginx is finally started, it may report that the drizzle shared library cannot be found. You can see Download the configuration file: /etc/ld.so.conf. After changing the configuration, remember to use lddconfig to re-validate it.
How to use it
First, in nginx Declare a mysql server in the http module
Copy code The code is as follows:
upstream backend {
Drizzle_server 172.21.107.247:3306 dbname=oneplus_user_sso password= user=root protocol= mysql;
}
The next step is to declare location processing
Copy code The code is as follows:
Location /mysql {
select * from t_user limit 1';
drizzle_query $my_sql;
drizzle_pass backend;
drizzle_connect_timeout 500ms; # default 60s
drizzle_send_query_ timeout 2s; # default 60s
drizzle_recv_cols_timeout 1s ; # default 60s
drizzle_recv_rows_timeout 1s; # default 60s
rds_json on; ://172.21.107.174/mysql,
can output a user's information, and the format is json
The above is the detailed content of How does Nginx implement asynchronous access to mysql?. For more information, please follow other related articles on the PHP Chinese website!