Skip to content

Instantly share code, notes, and snippets.

@cobbweb
Created July 29, 2011 04:19
Show Gist options
  • Select an option

  • Save cobbweb/1113125 to your computer and use it in GitHub Desktop.

Select an option

Save cobbweb/1113125 to your computer and use it in GitHub Desktop.

Revisions

  1. Andrew Cobby revised this gist Jul 29, 2011. 1 changed file with 64 additions and 0 deletions.
    64 changes: 64 additions & 0 deletions serverctl.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    #!/bin/bash
    NGINX=`brew --prefix nginx`'/sbin/nginx'
    PHPFPM=`brew --prefix php`'/sbin/php-fpm'
    PHPFPMCONFIG=`brew --prefix php`'/etc/php-fpm.conf'
    PIDPATH='/var/run'

    if [ $1 = "start" ]; then
    echo "Starting php-fpm ..."
    sudo $PHPFPM -y $PHPFPMCONFIG
    echo "Starting nginx ..."
    sudo $NGINX
    echo "Done!"
    elif [ $1 = "stop" ]; then
    echo "Stopping nginx ..."
    sudo kill `cat $PIDPATH/nginx.pid`
    echo "Stopping php-fpm ..."
    sudo kill `cat $PIDPATH/php-fpm.pid`
    echo "Done!"
    elif [ $1 = "restart" ]; then
    echo "Stopping nginx ..."
    sudo kill `cat $PIDPATH/nginx.pid`
    echo "Stopping php-fpm ..."
    sudo kill `cat $PIDPATH/php-fpm.pid`
    echo "Starting php-fpm ..."
    sudo $PHPFPM
    echo "Starting nginx ..."
    sudo $NGINX
    echo "Done!"
    elif [ $1 = "nginx" ]; then
    if [ $2 = "start" ]; then
    echo "Starting nginx ..."
    sudo $NGINX
    elif [ $2 = "stop" ]; then
    echo "Stopping nginx ..."
    sudo kill `cat $PIDPATH/nginx.pid`
    elif [ $2 = "restart" ]; then
    echo "Stopping nginx ..."
    sudo kill `cat $PIDPATH/nginx.pid`
    echo "Starting nginx ..."
    sudo $NGINX
    else
    echo "Valid commands for nginx: start | stop | restart"
    fi
    elif [ $1 = "php" ] || [ $1 = "php-fpm" ]; then
    if [ $2 = "start" ]; then
    echo "Starting php-fpm ..."
    sudo $PHPFPM
    elif [ $2 = "stop" ]; then
    echo "Stopping php-fpm ..."
    sudo kill `cat $PIDPATH/php-fpm.pid`
    elif [ $2 = "restart" ]; then
    echo "Stopping php-fpm ..."
    sudo kill `cat $PIDPATH/php-fpm.pid`
    echo "Starting php-fpm ..."
    sudo $PHPFPM
    else
    echo "Valid commands for php-fpm: start | stop | restart"
    fi
    echo "Valid commands: "
    echo "start | stop | restart"
    echo "----------------------------------------"
    echo "nginx (start | stop | restart)"
    echo "php | php-fpm (start | stop | restart)"
    fi
  2. Andrew Cobby revised this gist Jul 29, 2011. 2 changed files with 1 addition and 2 deletions.
    2 changes: 1 addition & 1 deletion example.conf
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ server {
    root /Users/Cobby/Sites/Example;

    if ($host = 'www.example.dev' ) {
    rewrite ^/(.*)$ http://mhemming.dev:8080/$1 permanent;
    rewrite ^/(.*)$ http://example.dev:8080/$1 permanent;
    }

    if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css|less)$") {
    1 change: 0 additions & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    #user Cobby;
    worker_processes 3;

  3. @invalid-email-address Anonymous created this gist Jul 29, 2011.
    43 changes: 43 additions & 0 deletions example.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    server {
    listen 8080;
    server_name example.dev www.example.dev;

    location / {
    root /Users/Cobby/Sites/Example;

    if ($host = 'www.example.dev' ) {
    rewrite ^/(.*)$ http://mhemming.dev:8080/$1 permanent;
    }

    if ($request_filename !~ "\.(js|htc|ico|gif|jpg|png|css|less)$") {
    rewrite ^(.*) /index.php last;
    }

    # If the file exists as a static file serve it directly without
    # running all the other rewite tests on it
    if (-f $request_filename) {
    # expires max;
    break;
    }
    }


    # if the request starts with our frontcontroller, pass it on to fastcgi
    location ~ \.php($|/)
    {
    set $script $uri;
    set $path_info "";

    if ($uri ~ "^(.+\.php)(/.+)") {
    set $script $1;
    set $path_info $2;
    }

    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /Users/Cobby/Sites/Example$script;
    fastcgi_param PATH_INFO $path_info;
    include /usr/local/etc/nginx/fastcgi_params;
    }

    }
    53 changes: 53 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@

    #user Cobby;
    worker_processes 3;

    error_log logs/error.log;
    #error_log logs/error.log notice;
    #error_log logs/error.log info;

    pid /var/run/nginx.pid;

    events {
    worker_connections 1024;
    }


    http {
    include mime.types;
    default_type application/octet-stream;

    sendfile on;

    keepalive_timeout 65;

    gzip on;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_min_length 1100;
    gzip_buffers 4 8k;
    gzip_proxied any;
    gzip_types
    # text/html is always compressed by HttpGzipModule
    text/css
    text/javascript
    text/xml
    text/plain
    text/x-component
    application/javascript
    application/json
    application/xml
    application/rss+xml
    font/truetype
    font/opentype
    application/vnd.ms-fontobject
    image/svg+xml;

    gzip_proxied expired no-cache no-store private auth;
    gzip_disable "MSIE [1-6]\.";
    gzip_vary on;

    include /Users/Cobby/conf/nginx/*.conf;

    }