View Poll Results: How useful is this script/tutorial?

Voters
63. You may not vote on this poll
  • Very Useful

    35 55.56%
  • Somewhat Useful

    15 23.81%
  • Somewhat Useless

    3 4.76%
  • Very Useless

    10 15.87%
Page 1 of 3 123 LastLast
Results 1 to 20 of 49

Thread: HowTo : NginX - The Apache Replacement

  1. #1
    Join Date
    Jun 2007
    Posts
    24

    Thumbs up HowTo : NginX - The Apache Replacement

    Introduction / Requirements

    Before reading this, please remember that NginX and Apache are fundamentally different.
    Therefore, not all functions can be emulated.

    When converting, be prepared to lose :
    - .htaccess
    I didn't do this, but I believe it should be doable for anyone who has too much time.
    To me, they are really useless as accessing a script in /docroot/1/2/3/4/5/6 will force the server to do 7 or 8 stat calls all the way upwards.
    Nothing near efficient if you ask me.

    - mod_rewrite
    This should be more doable than .htaccess in terms of implementing, as NginX has a powerful rewrite module in place.
    However, I don't like extra stuff done per access, so this isn't useful for me.

    In turn, you will gain :
    - The ability to handle sync-floods and thousands of concurrent connections
    - Use FastCGI for each user, creating a secure environment.
    - Set a limit of FastCGI processes per user.
    - Use php_admin_value and php_admin_flag with FastCGI
    - Drastic Speed Improvements!

    ==========================================================

    How To Install

    Part 1 : NginX

    1. Visit their website at http://www.nginx.net/
    2. On their homepage, download either the stable or developmental version.

    *Note: I went for the developmental version, but it doesn't really matter.*
    *The command below is valid as of time of posting, but will probably be outdated.

    3. Execute :

    Code:
    wget http://sysoev.ru/nginx/nginx-0.6.5.tar.gz
    tar -xzf nginx-0.6.5.tar.gz
    cd nginx-0.6.5
    4. Configure according to your preference. I chose this :

    Code:
    ./configure --with-http_stub_status_module --with-openssl=/usr/lib/openssl
    make
    make install
    This ends the nginx install.

    Part 2 : PHP

    1. Prepare your configuration options. If PHP is already installed, create a phpinfo(); page and extract the configuration line.

    2. Download the latest version of PHP, extract and enter that directory.

    3. Execute

    Code:
    ./configure --enable-fastcgi ... (Insert your configuration)
    make
    make install
    This ends the PHP install.

    Part 3 : Spawn FCGI Script

    We need to download LightTPD to get it's spawn-fcgi.

    1. To get it, download it from http://www.lighttpd.net.

    2. Download, extract, and then run :

    Code:
    ./configure
    make
    cd src
    cp ./spawn-fcgi /usr/local/bin/spawn-fcgi
    3. Try running /usr/local/bin/spawn-fcgi. Make sure it exists and returns this :

    Code:
    spawn-fcgi-1.4.15 - spawns fastcgi processes
    4. You can remove the extracted folder. lighttpd has not been installed as make install was not executed.

    Part 4 : Apache Parser

    I've written a parser to parse Apache configuration (attached to this post).

    1. Download the attachment, rename it nginx.php and place it in /etc/init.d/

    2. Execute :

    Code:
    chmod 700 nginx.php
    3. Use your favourite editor nano/pico/vi to open nginx.php.

    4. At the top of the file, you should see :

    Code:
    #!/usr/local/bin/php -n
    Replace /usr/local/bin/php with wherever your PHP binary is.
    Be careful NOT to remove the ending -n.

    5. The top part of the file (after that first line) should look like :

    Code:
    // Configuration Section
    $nginx_init = "/etc/init.d/nginx";
    $apache_config = "/etc/httpd/conf/httpd.conf";
    $da_vhosts = "/etc/httpd/conf/extra/directadmin-vhosts.conf";
    $tmp_folder = "/tmp/";
    $debug_level = 0; // 0 => FATAL, 1 => WARN, 2 => INFO
    
    $killall_bin = "/usr/bin/killall";
    $spawn_bin = "/usr/local/bin/spawn-fcgi";
    
    // Nginx Configuration
    $nginx_config = "/usr/local/nginx/conf/nginx.conf";
    $nginx_bin = "/usr/local/nginx/sbin/nginx";
    $mod_status = true;
    
    // PHP Configuration
    $php_childs = 3;
    $php_bin = "/opt/php/bin/php-cgi";
    $php_startport = 11000;
    Make sure the file paths are correct. For example, my PHP is located in /opt/php.
    Yours probably isn't.

    Some particularly important variables :

    $nginx_init - Where the controllable nginx init script will be. Leaving as-is is probably fine.
    $da_vhosts - This file must contain the list of includes of every user's httpd.conf
    $tmp_folder - The temporary folder. Must be world writable.
    $php_startport - The PHP FastCGI will bind to a port starting from this number.

    6. Execute the php script was rewrite-init as the parameter.

    Eg.
    Code:
    /etc/init.d/nginx.php rewrite-init
    7. The init file will be written to wherever you specified it previously.

    8. You can now run [init_file] start/stop/restart/reload/graceful/status.

    Part 5 : DirectAdmin Touchup

    1. Open /usr/local/directadmin/data/admin/services.status in a text editor.

    2. Replace httpd=ON with nginx=ON.

    3. Execute : (remember to replace INIT_FILE below with where your nginx init file is)

    Code:
    mv /etc/init.d/httpd /etc/init.d/httpd.old
    ln -vs INIT_FILE /etc/init.d/httpd
    Part 6 : htscanner (Optional)
    This module installs a PHP plugin to emulate Apache's scanning for PHP options.

    1. Locate where your PHP Pecl is :

    Code:
    locate pecl
    2. Using the full path of pecl found, execute :

    Code:
    /location/to/pecl install htscanner
    Installation has completed from this point onwards.
    Please reply to this post if you find any bugs.


    ChangeLog
    v0.90 - FastCGI accepts php_admin_value, etc. configuration and uses its own user.
    v1.00 - First Public Release.
    v1.01 - Introduced new tutorial - htscanner
    Attached Files Attached Files
    Last edited by tsj5j; 08-04-2007 at 11:48 PM.

  2. #2
    Join Date
    Jun 2003
    Location
    California
    Posts
    26,123
    No reason to post exactly the same twice. I deleted the other one.

    Jeff
    +1 951 643-5345
    Third-Party DirectAdmin administration and support
    Dedicated Servers, Dedicated Reseller Accounts
    NoBaloney Internet Services div. Qnito Incorporated
    848 North Rainbow Blvd., Suite #3789
    Las Vegas, NV 89107-1103

  3. #3
    Join Date
    Jan 2007
    Posts
    347
    very nice!
    i want to make nginx handle static content on front of apache.
    will try to modify a bit.
    thanks

  4. #4
    Join Date
    Jun 2007
    Posts
    24
    Quote Originally Posted by jackc View Post
    very nice!
    i want to make nginx handle static content on front of apache.
    will try to modify a bit.
    thanks
    You'll probably want to change the binding port as well as the not remove apache's own init script.

  5. #5
    Join Date
    Jan 2007
    Posts
    347
    hi, I want to ask, is the bandwidth usage able to calculate? NginX seems have different log format.

  6. #6
    Join Date
    Jun 2007
    Posts
    24
    Quote Originally Posted by jackc View Post
    hi, I want to ask, is the bandwidth usage able to calculate? NginX seems have different log format.
    DirectAdmin uses simply the byte format log of Apache to do calculation, and nginx supports custom formats, so I simply created a format in the config file to output only bytes.

    Nginx also has another Apache-style full log which webalizer uses. It outputs that as well.

  7. #7
    Join Date
    Jan 2007
    Posts
    347
    got it. thanks!

  8. #8
    Join Date
    May 2007
    Posts
    22
    Hi,

    I tried to follow this how-to, and not succeed.



    ./configure --with-http_stub_status_module --with-openssl=/usr/lib/openssl
    It shows an error and aks to either add a no httpd rewrite module clause and one more option, its not in how-to what do do with this error.

    Part 2 : PHP

    1. Prepare your configuration options. If PHP is already installed, create a phpinfo(); page and extract the configuration line.
    I am installing on a DA server, So what I am supposed to do?

    Part 3 : Spawn FCGI Script

    We need to download LightTPD to get it's spawn-fcgi.

    1. To get it, download it from http://www.lighttpd.net.
    I got the download of fast-cgi from fastcgi.com and when I installed by make command, You have specified to switch directory to src, but there is no directory inside named src.

    Please explain how to perform all steps in as a detailed How-to for a noob.

    Will this install make exactly same thing and normal working as it was working in apache?

    Thanks for the info and initiative.

  9. #9
    Join Date
    Mar 2007
    Location
    Kharkov, Ukraine
    Posts
    18
    Quote Originally Posted by SoCal View Post
    It shows an error and aks to either add a no httpd rewrite module clause and one more option, its not in how-to what do do with this error.
    Try to think.. Simple:
    yum install pcre-devel

  10. #10
    Join Date
    Feb 2007
    Posts
    13
    There seems to be a bug in the parser, I've got a vhost entry in an apache httpd.conf, but it's got loads of domain pointers in the serveralias, so has about 4-5 server alias entries. The parser only manages about 5 pointers. I tried adding them manually, but whenever I start nginx using the script, it overwrites my conf file.

  11. #11
    Join Date
    Aug 2006
    Location
    LT, EU
    Posts
    6,744
    conf/mime.types in nginx.php should be just mime.types, because conf/mime.types full path is /usr/local/nginx/conf/conf/mime.types, the same problem with conf/fastcgi.conf, it should be replaced to fastcgi_params. And for debian systems you should use killall instead of killproc in /etc/init.d/nginx. These lines are not needed too:
    Code:
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    # Source networking configuration.
    . /etc/sysconfig/network
    Last edited by smtalk; 06-15-2008 at 11:13 PM.
    Martynas Bendorius
    MB Martynas IT. Professional server management company. Official DirectAdmin, CloudLinux, LiteSpeed and Comodo partners.

  12. #12
    Join Date
    Oct 2006
    Posts
    36

    SSL implementation

    Hello,

    Is there any way to impelement apache openssl to nginx ?

    when we restart nginx it gets all confs form

    /etc/httpd/conf/extra/directadmin-vhosts.conf.
    But it is not includes ;

    SSLEngine on
    SSLCertificateFile /usr/local/directadmin/data/users/user_name/domains/domain.com.cert
    SSLCertificateKeyFile /usr/local/directadmin/data/users/user_name/domains/domain.com.key
    SSLCACertificateFile /usr/local/directadmin/data/users/user_name/domains/domain.com.cacert
    How can we convert SSL lines form httpd.conf to nginx.conf wiht nginx ssl format like this?
    server {
    listen 443;

    ssl on;
    ssl_certificate /etc/ssl/certs/myssl.crt;
    ssl_certificate_key /etc/ssl/private/myssl.key;
    Last edited by Yolte; 06-17-2008 at 01:33 AM.

  13. #13
    Join Date
    May 2008
    Posts
    31
    hi, i have follow the how-to step by step, but i can execute php on my server, i get this

    Code:
    502 Bad Gateway
    nginx/0.6.5
    just its a phpinfo php file, any suggestion or help with this???

    and when i try to enter to phpmyadmin www.domain.tld/phpmyadmin i get

    Code:
    404 Not Found
    nginx/0.6.5

    Thanks for your reply and help
    Regards
    Dmtinc
    Last edited by dmtinc; 07-05-2008 at 05:56 PM. Reason: add another problem

  14. #14
    Join Date
    Dec 2007
    Location
    Moscow
    Posts
    161
    What is the output of /usr/local/bin/spawn-fcgi?
    wbr,
    Boris.

  15. #15
    Join Date
    May 2008
    Posts
    31
    Quote Originally Posted by proHSP View Post
    What is the output of /usr/local/bin/spawn-fcgi?
    Code:
    /usr/local/bin/spawn-fcgi
    Usage: spawn-fcgi [options] -- <fcgiapp> [fcgi app arguments]
    
    spawn-fcgi v1.4.19 - spawns fastcgi processes
    
    Options:
     -f <fcgiapp> filename of the fcgi-application
     -a <addr>    bind to ip address
     -p <port>    bind to tcp-port
     -s <path>    bind to unix-domain socket
     -C <childs>  (PHP only) numbers of childs to spawn (default 5)
     -P <path>    name of PID-file for spawed process
     -n           no fork (for daemontools)
     -v           show version
     -h           show this help
    (root only)
     -c <dir>     chroot to directory
     -u <user>    change to user-id
     -g <group>   change to group-id
    Thanks For Your Help

    Regards v,v

  16. #16
    Join Date
    Dec 2007
    Location
    Moscow
    Posts
    161
    and /usr/local/bin/spawn-fcgi -f /opt/php/bin/php-cgi -p 11000?
    wbr,
    Boris.

  17. #17
    Join Date
    Jul 2008
    Posts
    1

    Red face

    very nice!
    i want to get a example of nginx configuration for PHP fastCGI's php_admin_value
    i don't know how to configure the php_admin_value of php in nginx's configuration

    Look forward the reply
    thanks

  18. #18
    Join Date
    Dec 2007
    Location
    Moscow
    Posts
    161
    Unfortunately, it is impossible, because nginx uses php as fastcgi, and fastcgi does not support php_admin_value.
    wbr,
    Boris.

  19. #19
    Join Date
    Aug 2006
    Location
    LT, EU
    Posts
    6,744
    It will be possible with PHP 5.3.0
    Martynas Bendorius
    MB Martynas IT. Professional server management company. Official DirectAdmin, CloudLinux, LiteSpeed and Comodo partners.

  20. #20
    Join Date
    Nov 2008
    Posts
    1
    I've got the following error executing /etc/init.d/nginx.php rewrite-init


    PHP Warning: PHP Startup: dbase: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: ldap: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: mbstring: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: mysql: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: mysqli: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: odbc: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: PDO: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: pdo_mysql: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: PDO_ODBC: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: pdo_pgsql: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: pdo_sqlite: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: pgsql: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    Rewrite completed.
    [root@mytrance init.d]# php -f /etc/init.d/nginx.php rewrite-init
    PHP Warning: PHP Startup: dbase: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: ldap: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: mbstring: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: mysql: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: mysqli: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: odbc: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: PDO: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: pdo_mysql: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: PDO_ODBC: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: pdo_pgsql: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: pdo_sqlite: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    PHP Warning: PHP Startup: pgsql: Unable to initialize module
    Module compiled with module API=20050922, debug=0, thread-safety=0
    PHP compiled with module API=20060613, debug=0, thread-safety=0
    These options need to match
    in Unknown on line 0
    Rewrite completed.
    Last edited by nightskiff; 11-10-2008 at 09:56 AM.

Page 1 of 3 123 LastLast

Similar Threads

  1. HOWTO: Using Nginx - best practices!
    By paix in forum How-To Guides
    Replies: 43
    Last Post: 10-16-2013, 01:29 PM
  2. Replies: 0
    Last Post: 12-31-2012, 10:25 AM
  3. Replies: 4
    Last Post: 12-21-2011, 10:56 PM
  4. Problem with nginx + apache
    By Mihalich in forum 3rd Party Software
    Replies: 4
    Last Post: 07-13-2009, 05:47 PM
  5. Need Nginx installed to replace Apache
    By Amaresh in forum Employment Opportunities
    Replies: 1
    Last Post: 10-09-2008, 02:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •