Skip to content

Instantly share code, notes, and snippets.

@colevscode
Created June 30, 2012 00:18
Show Gist options
  • Save colevscode/3021545 to your computer and use it in GitHub Desktop.
Save colevscode/3021545 to your computer and use it in GitHub Desktop.

Revisions

  1. Cole revised this gist Jun 30, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion nginx.rb
    Original file line number Diff line number Diff line change
    @@ -110,7 +110,6 @@ def startup_plist
    </plist>
    EOPLIST
    end
    end

    protected
    def prepare_nginx_upload_module
  2. Cole revised this gist Jun 30, 2012. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion nginx.rb
    Original file line number Diff line number Diff line change
    @@ -53,7 +53,6 @@ def install

    args << passenger_config_args if ARGV.include? '--with-passenger'
    args << "--with-http_dav_module" if ARGV.include? '--with-webdav'
    args << passenger_config_args if ARGV.include? '--with-passenger'

    if ARGV.include? '--with-upload-module'
    prepare_nginx_upload_module
  3. Cole revised this gist Jun 30, 2012. 1 changed file with 69 additions and 54 deletions.
    123 changes: 69 additions & 54 deletions nginx.rb
    Original file line number Diff line number Diff line change
    @@ -15,64 +15,104 @@ class Nginx < Formula

    skip_clean 'logs'

    # Changes default port to 8080
    def patches
    # Changes default port to 8080
    # Adds code to detect PCRE installed in a non-standard HOMEBREW_PREFIX
    DATA
    end

    def options
    [
    ['--with-passenger', "Compile with support for Phusion Passenger module"],
    ['--with-webdav', "Compile with support for WebDAV module"],
    ['--with-upload-module', "Compile with upload module by Valery Kholodkov"]
    ]
    end

    def passenger_config_args
    passenger_root = `passenger-config --root`.chomp

    if File.directory?(passenger_root)
    return "--add-module=#{passenger_root}/ext/nginx"
    end

    puts "Unable to install nginx with passenger support. The passenger"
    puts "gem must be installed and passenger-config must be in your path"
    puts "in order to continue."
    exit
    end

    def install
    configure_args = [
    "--prefix=#{prefix}",
    "--with-http_ssl_module",
    "--with-ld-opt=-L/usr/local/lib",
    ]


    configure_args << passenger_config_args if ARGV.include? '--with-passenger'

    def install
    args = ["--prefix=#{prefix}",
    "--with-http_ssl_module",
    "--with-pcre",
    "--with-cc-opt='-I#{HOMEBREW_PREFIX}/include'",
    "--with-ld-opt='-L#{HOMEBREW_PREFIX}/lib'",
    "--conf-path=#{etc}/nginx/nginx.conf",
    "--pid-path=#{var}/run/nginx.pid",
    "--lock-path=#{var}/nginx/nginx.lock"]

    args << passenger_config_args if ARGV.include? '--with-passenger'
    args << "--with-http_dav_module" if ARGV.include? '--with-webdav'
    args << passenger_config_args if ARGV.include? '--with-passenger'

    if ARGV.include? '--with-upload-module'
    prepare_nginx_upload_module

    configure_args << "--add-module=./#{nginx_upload_module_dirname}"
    args << "--add-module=./#{nginx_upload_module_dirname}"
    end

    system "./configure", *configure_args
    system "./configure", *args
    system "make"
    system "make install"
    man8.install "objs/nginx.8"

    plist_path.write startup_plist
    plist_path.chmod 0644
    end

    def caveats
    <<-CAVEATS
    In the interest of allowing you to run `nginx` without `sudo`, the default
    port is set to localhost:8080.
    If you want to host pages on your local machine to the public, you should
    change that to localhost:80, and run `sudo nginx`. You'll need to turn off
    any other web servers running port 80, of course.
    CAVEATS
    def caveats; <<-EOS.undent
    In the interest of allowing you to run `nginx` without `sudo`, the default
    port is set to localhost:8080.
    If you want to host pages on your local machine to the public, you should
    change that to localhost:80, and run `sudo nginx`. You'll need to turn off
    any other web servers running port 80, of course.
    You can start nginx automatically on login running as your user with:
    mkdir -p ~/Library/LaunchAgents
    cp #{plist_path} ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/#{plist_path.basename}
    Though note that if running as your user, the launch agent will fail if you
    try to use a port below 1024 (such as http's default of 80.)
    EOS
    end

    def startup_plist
    return <<-EOPLIST
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>#{plist_name}</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>UserName</key>
    <string>#{`whoami`.chomp}</string>
    <key>ProgramArguments</key>
    <array>
    <string>#{HOMEBREW_PREFIX}/sbin/nginx</string>
    </array>
    <key>WorkingDirectory</key>
    <string>#{HOMEBREW_PREFIX}</string>
    </dict>
    </plist>
    EOPLIST
    end
    end

    protected
    def prepare_nginx_upload_module
    ohai "Downloading #{nginx_upload_module_url}"
    @@ -96,39 +136,14 @@ def nginx_upload_module_dirname
    end

    __END__
    --- a/auto/lib/pcre/conf
    +++ b/auto/lib/pcre/conf
    @@ -155,6 +155,22 @@ else
    . auto/feature
    fi

    + if [ $ngx_found = no ]; then
    +
    + # Homebrew
    + HOMEBREW_PREFIX=${NGX_PREFIX%Cellar*}
    + ngx_feature="PCRE library in ${HOMEBREW_PREFIX}"
    + ngx_feature_path="${HOMEBREW_PREFIX}/include"
    +
    + if [ $NGX_RPATH = YES ]; then
    + ngx_feature_libs="-R#{HOMEBREW_PREFIX}/lib -L#{HOMEBREW_PREFIX}/lib -lpcre"
    + else
    + ngx_feature_libs="-L#{HOMEBREW_PREFIX}/lib -lpcre"
    + fi
    +
    + . auto/feature
    + fi
    +
    if [ $ngx_found = yes ]; then
    CORE_DEPS="$CORE_DEPS $REGEX_DEPS"
    CORE_SRCS="$CORE_SRCS $REGEX_SRCS"
    --- a/conf/nginx.conf
    +++ b/conf/nginx.conf
    @@ -33,7 +33,7 @@
    #gzip on;

    server {
    - listen 80;
    + listen 8080;
    server_name localhost;

    #charset koi8-r;
  4. Cole revised this gist Jun 30, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.rb
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ def install
    configure_args = [
    "--prefix=#{prefix}",
    "--with-http_ssl_module",
    "--with-ld-opt=\"-L /usr/local/lib\"",
    "--with-ld-opt=-L/usr/local/lib",
    ]


  5. Cole revised this gist Jun 30, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.rb
    Original file line number Diff line number Diff line change
    @@ -45,7 +45,7 @@ def install
    configure_args = [
    "--prefix=#{prefix}",
    "--with-http_ssl_module",
    "--with-ld-opt='-L /usr/local/lib'",
    "--with-ld-opt=\"-L /usr/local/lib\"",
    ]


  6. Cole revised this gist Jun 30, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion nginx.rb
    Original file line number Diff line number Diff line change
    @@ -44,7 +44,8 @@ def passenger_config_args
    def install
    configure_args = [
    "--prefix=#{prefix}",
    "--with-http_ssl_module"
    "--with-http_ssl_module",
    "--with-ld-opt='-L /usr/local/lib'",
    ]


  7. Cole created this gist Jun 30, 2012.
    133 changes: 133 additions & 0 deletions nginx.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,133 @@
    require 'formula'

    class Nginx < Formula
    url 'http://nginx.org/download/nginx-1.2.1.tar.gz'
    head 'http://nginx.org/download/nginx-1.3.2.tar.gz'
    homepage 'http://nginx.org/'

    if ARGV.include? '--HEAD'
    @md5='7a4f8e26b76bf9f24f884317f5614338'
    else
    @md5='ceacae12d66d1f021bf3737a0269b6f4'
    end

    depends_on 'pcre'

    skip_clean 'logs'

    def patches
    # Changes default port to 8080
    # Adds code to detect PCRE installed in a non-standard HOMEBREW_PREFIX
    DATA
    end

    def options
    [
    ['--with-passenger', "Compile with support for Phusion Passenger module"],
    ['--with-upload-module', "Compile with upload module by Valery Kholodkov"]
    ]
    end

    def passenger_config_args
    passenger_root = `passenger-config --root`.chomp

    if File.directory?(passenger_root)
    return "--add-module=#{passenger_root}/ext/nginx"
    end

    puts "Unable to install nginx with passenger support. The passenger"
    puts "gem must be installed and passenger-config must be in your path"
    puts "in order to continue."
    exit
    end

    def install
    configure_args = [
    "--prefix=#{prefix}",
    "--with-http_ssl_module"
    ]


    configure_args << passenger_config_args if ARGV.include? '--with-passenger'


    if ARGV.include? '--with-upload-module'
    prepare_nginx_upload_module

    configure_args << "--add-module=./#{nginx_upload_module_dirname}"
    end

    system "./configure", *configure_args
    system "make install"
    end

    def caveats
    <<-CAVEATS
    In the interest of allowing you to run `nginx` without `sudo`, the default
    port is set to localhost:8080.
    If you want to host pages on your local machine to the public, you should
    change that to localhost:80, and run `sudo nginx`. You'll need to turn off
    any other web servers running port 80, of course.
    CAVEATS
    end

    protected
    def prepare_nginx_upload_module
    ohai "Downloading #{nginx_upload_module_url}"
    curl "-O", nginx_upload_module_url

    ohai "Extracting #{nginx_upload_module_filename}"
    safe_system "/usr/bin/tar", "-zxvf", nginx_upload_module_filename
    end

    def nginx_upload_module_url
    "http://www.grid.net.ru/nginx/download/nginx_upload_module-2.2.0.tar.gz"
    end

    def nginx_upload_module_filename
    @nginx_upload_module_filename ||= nginx_upload_module_url.split('/').last
    end

    def nginx_upload_module_dirname
    nginx_upload_module_filename.sub(".tar.gz", "")
    end
    end

    __END__
    --- a/auto/lib/pcre/conf
    +++ b/auto/lib/pcre/conf
    @@ -155,6 +155,22 @@ else
    . auto/feature
    fi

    + if [ $ngx_found = no ]; then
    +
    + # Homebrew
    + HOMEBREW_PREFIX=${NGX_PREFIX%Cellar*}
    + ngx_feature="PCRE library in ${HOMEBREW_PREFIX}"
    + ngx_feature_path="${HOMEBREW_PREFIX}/include"
    +
    + if [ $NGX_RPATH = YES ]; then
    + ngx_feature_libs="-R#{HOMEBREW_PREFIX}/lib -L#{HOMEBREW_PREFIX}/lib -lpcre"
    + else
    + ngx_feature_libs="-L#{HOMEBREW_PREFIX}/lib -lpcre"
    + fi
    +
    + . auto/feature
    + fi
    +
    if [ $ngx_found = yes ]; then
    CORE_DEPS="$CORE_DEPS $REGEX_DEPS"
    CORE_SRCS="$CORE_SRCS $REGEX_SRCS"
    --- a/conf/nginx.conf
    +++ b/conf/nginx.conf
    @@ -33,7 +33,7 @@
    #gzip on;

    server {
    - listen 80;
    + listen 8080;
    server_name localhost;

    #charset koi8-r;