Alpha
Share and Organize Code
login register
HotNewTop
F.A.Q.
1. To begin adding code first register.
2. Create your own tags for code that you add.
3. To see your own code click Me, to see all code click Everyone, or filter by people rob.
4. To follow a user, click on their username, rob and hit follow.
5. Add other code to your library by clicking the
button near the code titles (note that you can not edit these codes).
6. To create a copy of a code that you can edit use fork.
7. If you can't find your code, double check your filter settings as you can filter by Category, User and Tag simultaneously.
8. Add comments to a code by clicking on it's title or the comments link underneath it.

Hide index.php in URL (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# --- Perform 301 canonical redirect to remove index.php
    location ^~ /index.php {
        rewrite ^/index.php(.*)$ $scheme://$server_name$1 permanent;
    }

# --- catch-all location block for all other URLs
    location / {

# --- note: do not add "$uri/" before @handler, if you have an "index index.php" directive, it will auto redirect to "index.php" and cause an infinite loop due to the location block above
        try_files $uri @handler;

# --- The 2 lines below are for htaccess
        auth_basic            "Restricted";
        auth_basic_user_file  /etc/nginx/web/htpasswd;
    }

# --- internally add index.php back to the request
    location @handler {
        rewrite ^ /index.php$uri break;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/tmpfpm/staging/php-fpm.sock;
        fastcgi_read_timeout 5m;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/web/public_html$fastcgi_script_name;
    }
[+] (21) more...
comments (0) flag fork

Nginx VHost Example (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# ----------------------------------------------------------- #
# This config redirects mail.domain.com to www.domain.com
# The rewrite rule can be taken out and actually server mail.domain.com
# Notice a socket connection is used for fastcgi ... this is better than using a TCP connection for performance. However PHP-FPM needs to be configured first so that those socket connections exist!!
# ----------------------------------------------------------- #
server {
    listen 0.0.0.0:80;
    server_name mail.domain.com;
    access_log off;
    error_log /var/log/nginx/mail-error.log debug;
    root /home/mail/public_html;

    location / {
        index index.php;
        rewrite ^/ http://www.domain.com/;
    }

    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/tmpfpm/prod/mail/php-fpm.sock;
        #fastcgi_pass 127.0.0.1:9000;
        fastcgi_read_timeout 5m;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /home/mail/public_html$fastcgi_script_name;
    }
        location ~ /\.ht* {
                deny  all;
        }
}
[+] (25) more...
comments (0) flag fork

Display Nginx Process and Workers (plain)

1
2
3
4
5
6
7
8
9
10
11
12
13
ps aux | grep nginx

# should show you something like this:
# root      5151  0.0  0.2 100128 58392 ?        Ss   Feb22   0:05 nginx: master process
# /usr/local/sbin/nginx -c /etc/nginx/nginx.conf
# nobody   19980  0.0  0.2 102828 62492 ? S    May03   6:12 nginx: worker process                        
# nobody   19981  0.0  0.2 102316 61908 ? S    May03   6:17 nginx: worker process                        
# nobody   19982  0.0  0.2 106484 64968 ? S    May03   6:30 nginx: worker process                        
# nobody   19983  0.0  0.2 102828 62012 ? S    May03   6:05 nginx: worker process                        
# nobody   19984  0.0  0.2 102572 62016 ? S    May03   6:18 nginx: worker process                        
# nobody   19985  0.0  0.2 102060 61876 ? S    May03   6:31 nginx: worker process

Notice there's 6 worker processes. The number of workers is set in nginx.conf
[+] (9) more...
comments (0) flag fork

Reload Nginx (plain)

1
2
3
4
5
6
7
8
9
# Test your config changes first before reloading the config with: nginx -t
# Reload Nginx Config:
nginx -s reload
# OR
/etc/init.d/nginx reload
# OR get the process id of the NginX Master process:
ps aux | grep nginx
# And lets say in this case, the Master PID = 15465, then reload the NginX process like so:
kill -HUP 15465
[+] (5) more...
comments (1) flag fork

Nginx CLI (plain)

1
2
3
4
5
6
# Display Nginx Command Line Options
nginx -h
# Display Nginx installed version
nginx -v
# TEST nginx config... ALWAYS do this before applying any config changes!!!
nginx -t
[+] (2) more...
comments (1) flag fork