Skip to content

Instantly share code, notes, and snippets.

View bachvtuan's full-sized avatar
🏡
make it works

Tuan Bach Van bachvtuan

🏡
make it works
View GitHub Profile
-e git+git@github.com:{company}/{repository-name}.git@{tag-version}#egg={package-name}
@bachvtuan
bachvtuan / guide.md
Created May 8, 2021 03:09 — forked from fyrebase/guide.md
Setup individual pools for PHP-FPM and NGINX - http://www.binarytides.com/php-fpm-separate-user-uid-linux/

Php-FPM

Php fpm is the new way to setup php to run with your webserver. Php-fpm is a fastcgi process manager for php that is totally separate from the webserver. The webserver communicates with fpm through a socket and passes the name of the script to execute. So fpm can run with any web server that is fastcgi compatible.

I recently moved from my old shared hosting to linode. Linode provides linux vps hosting at economic prices. However the servers are totally unmanaged are just raw linux machines that have shell access. So through the shell you have to setup everything including the web server, php and the web files.

So this time I decided to go with the combination of nginx and php-fpm. I had multiple sites to setup on this new webserver. Nginx deals with these through separate server blocks (aka vhost in apache). However there was another thing needed. Php on each site should run with its own user and not the nginx common user named www-data.

Running each site with its own uid/gid is more secure and

@bachvtuan
bachvtuan / gist:89a9e5861abd927ad355687d465671a1
Last active July 31, 2020 02:14
Permission for normal user access on nginx upload folder
# Create group name normaluser-web
sudo groupadd normaluser-web
# Add normal user to group
usermod -a -G normaluser-web normaluser
# Add www-data to group
usermod -a -G normaluser-web www-data
# Set ownship folder to user with new group
chown -R normaluser:normaluser-web upload/
# Set 775 to www-data can write too.
chmod 775 upload/
@bachvtuan
bachvtuan / gist:63ca70ac09d2e3e76dc45f6c7b5cd47d
Created June 3, 2020 04:05
Good Config For Wordpress site to prevent attack
server {
listen 80;
server_name yoursite.com;
rewrite ^ https://$server_name$request_uri? permanent;
}
server {
listen 443;
server_name yoursite.com www.yoursite.com;
# listen [::]:80 default_server ipv6only=on;
@bachvtuan
bachvtuan / bitcoin_transaction.js
Created September 13, 2016 03:24
Send bitcoin transaction to multiple addresses
/**
* package.json
"devDependencies": {
"bitcore-lib": "^0.13.18",
"async": "0.9.0",
"request": "2.53.0"
}
*/
@bachvtuan
bachvtuan / upload.js
Last active August 11, 2016 09:17
[ Nodejs ]Upload unicode file to Dropbox V2
var request = require('request');
var fs = require('fs');
//Reference https://www.dropboxforum.com/hc/en-us/community/posts/207458626-HTTP-header-Dropbox-API-Arg-could-not-decode-input-as-JSON
var charsToEncode = /[\u007f-\uffff]/g;
function http_header_safe_json(v) {
return JSON.stringify(v).replace(charsToEncode,
function(c) {
return '\\u'+('000'+c.charCodeAt(0).toString(16)).slice(-4);
@bachvtuan
bachvtuan / send_sms.js
Last active April 11, 2018 10:25
Send SMS Amazon SNS Nodejs
/**
* @Author: bachvtuan@gmail.com
* to_number: String : user phone number
* message: String : sms message
* func_callback: function : callback function( status )
* Reference links :
* https://gist.github.com/stuartmyles/8099723
* http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SNS.html#deleteTopic-property
*/
@bachvtuan
bachvtuan / slug.go
Last active September 27, 2015 08:17
Generate unicode slug in Golang
package main
import (
"fmt"
"unicode"
"code.google.com/p/go.text/transform"
"code.google.com/p/go.text/unicode/norm"
"regexp"
"strings"
)