Skip to content

Instantly share code, notes, and snippets.

@Taymindis
Last active May 3, 2018 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Taymindis/f4e5027823ddd79d5f1e8f318965bc2f to your computer and use it in GitHub Desktop.
Save Taymindis/f4e5027823ddd79d5f1e8f318965bc2f to your computer and use it in GitHub Desktop.
Nginx-c-function sample nginx.conf
# nginx.conf
### link to your local path and call ###
server {
listen 8888;
...
ngx_http_c_func_link_lib "/path/to/your/libcfuntest.so";
...
...
location = /testCFunGreeting {
# if not variable specified, direct write response out
ngx_http_c_func_call "my_app_simple_get_greeting";
}
}
### sharing app built in memory with server 1 if the path are same with server 1 ###
server {
listen 8989;
...
ngx_http_c_func_link_lib "/path/to/your/libcfuntest.so"; # sharing data memory with server 1 if the path are same with server 1
...
...
location = /testCFunGreeting {
# if variable specified, not response write out, but it stored into myResponseVariable
ngx_http_c_func_call "my_app_simple_get_greeting" respTo=myResponseVariable;
return 200 $myResponseVariable;
}
}
### another application ###
server {
listen 8999;
...
ngx_http_c_func_link_lib "/path/to/your/libcfuntest2.so"; # another application
...
...
location = /testPost {
add_header Allow "GET, POST, HEAD" always;
if ( $request_method !~ ^(POST)$ ) {
return 405;
}
ngx_http_c_func_call "my_2nd_app_simple_get_token";
}
}
### link to your http path and call ###
server {
listen 9888;
...
## Download application from cloud repo e.g. ngx_http_c_func_download_and_link_lib <download_link> <dest_link_file>
ngx_http_c_func_download_and_link_lib "http://abc.com/repos/libcfuntest.so" "/etc/nginx/libcfuntest3.so"
...
...
location = /testPost {
add_header Allow "GET, POST, HEAD" always;
if ( $request_method !~ ^(POST)$ ) {
return 405;
}
ngx_http_c_func_call "my_3rd_app_simple_get_token";
}
}
### link to your https path and call ###
server {
listen 9898;
...
## Download application from cloud repo with extra header e.g. ngx_http_c_func_download_and_link_lib <download_link> <headers> <dest_link_file>
ngx_http_c_func_download_and_link_lib "https://abc.com/repos/libcfuntest.so" "Accept-Language:en_US\r\nAuthorization:Bearer KA.eyJ2ZXJzaadlasdlaldhjHJ2h3ldjklsjaklcjkljasdklcmasaskdaJxdkL3ftjM\r\n" "/etc/nginx/libcfuntest4.so"
...
...
location = /testPost {
add_header Allow "GET, POST, HEAD" always;
if ( $request_method !~ ^(POST)$ ) {
return 405;
}
ngx_http_c_func_call "my_other_app_simple_get_token";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment