Document directory
- 1. Select a version
- 2. Pay attention to the directory structure
- Iii. Dependency
- 4. Install Nginx
- V. Use
- Vi. Summary
- VII. Appendix: Compile-time options
Download the nginx source code package (from http://wiki.nginx.org/nginxchs)
To compile nginx, you must specify pcre, zlib, and openssl. Since my system does not install these packages, I will not install deb packages and run them directly.
Then extract the nginx-0.6.32 package to the/opt directory, enter the nginx directory, execute:
#. /Configure -- sbin-path =/usr/local/sbin -- with-http_ssl_module -- with-pcre = .. /pcre-7.7 -- with-zlib = .. /zlib-1.2.3 -- with-openssl = .. openssl-0.9.8g
# Make & make install
If. /configure errors occur. query problems in sequence. Generally, no errors will occur, but you must install build-essential. If not, run the following command to install the compiling environment:
# Apt-get install build-essential
The default nginx installation directory is/usr/local/nginx, including:
/Usr/local/nginx/sbin # control the nginx Startup File
/Usr/local/nginx/conf # configuration file
/Usr/local/nginx/html # default webpage File
/Usr/local/nginx/logs # Log File
++ ++
Turn: http://docs.google.com/View? Docid = dhf86kr9_302cssf49dh & hgd = 1
Nginx("Engine x") is a high-performance HTTP and reverse proxy server. Compared with Apache, Nginx is lightweight and easy to configure. This article introduces how to use the source on Ubuntu hard drive, to compile Nginx.
1. Select a version
Most of the reasons for compiling Nginx from the source code are that the latest version can be used, not limited to the old version installed in aptitude. When writing this article, the latest stable version of Nginx is 0.6.31 (you can check the latest version on the official site of Nginx), while aptitude is installed with version 0.5.33.
Of course, using source code compilation will be a little more troublesome than aptitude and will require DIY for future updates. If you like it conveniently and are not very sensitive to the version, you can refer to the previous article "Install Nginx with aptitude" using aptitude for installation.
2. Pay attention to the directory structure
Note that the directory structure is different when Nginx is installed using aptitude and Nginx is compiled and installed from the source code, nginx installed with aptitude will create the "sites-available" and "sites-enabled" directories in its installation directory (it seems like you want to install the Apache directory structure on Ubuntu ), during source code compilation, these two directories will not be automatically created. Later we will explain how to make the two directories consistent (although you do not need to modify them, however, placing each web configuration in a configuration file is better than mixing them together ).
Iii. Dependency
When aptitude is used for installation, the system will install all dependent packages together, but the source code compilation is not so intelligent. We need to find the required dependent package, then install it manually. Fortunately, this is not complicated, and it is not much complicated, such as pcre, ssl, and zlib. The installation method is relatively simple:
Sudo aptitude install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev
4. Install Nginx
OK. The preparation is complete. It is time to download and install Nginx.
1. Create a directory
Mkdir ~ /Sources
Cd ~ /Sources/
2. Download the source code
Wget http://sysoev.ru/nginx/nginx-0.6.31.tar.gz
3. Decompress
Tar-zxvf nginx-0.6.31.tar.gz
...
Cd nginx-0.6.31/
4. Select the required compilation options.
There are still a lot of Nginx compilation Options. You can refer to the Install Options page of Nginx wiki or appendix 1 below to learn more about each option, basically, the positions and modules are customized. Here we only need two modules (if you have your own requirements, DIY). They are:
1) -- sbin-path =/usr/local/sbin
Compiling Nginx from source code will be installed in the/usr/local/nginx directory (you can use the -- prefix = <path> parameter to specify the desired location ), then, the BIND file will be placed in/usr/local/nginx/sbin/nginx, although clear, but unlike our general habits (we are used to searching for binfiles under/usr/local/sbin );
2) -- with-http_ssl_module
There is nothing to say about this, mainly to provide https access support.
5. Compile
./Configure -- sbin-path =/usr/local/sbin -- with-http_ssl_module
The compilation will not take a long time. When the compilation is completed, you will see the following information on the screen:
...
Nginx path prefix: "/usr/local/nginx"
Nginx binary file: "/usr/local/sbin"
Nginx configuration file: "/usr/local/nginx/conf/nginx. conf"
...
The above prompt involves the path information of several important nginx files.
6. Make & make install
It's almost finished. Now make it.
Make
...
Sudo make install
7. chmod
You also need to grant the binfile the execution permission, which is also relatively simple:
Chmod + x/usr/local/sbin/nginx
V. Use
After the installation is complete, try to use it.
1. Start
Sudo/usr/local/sbin/nginx (start)/usr/local/sbin/nginx-s stop (stop)/usr/local/sbin/nginx-s reload (restart)
Then navigate your browser to http: // IP to see the default welcome interface, as shown below:
2. Stop
If you have used apache or see the previous article using aptitude to install Nginx, you may. the nginx script under d/is quite impressive, using/etc/init. d/nginx can be directly started or stopped. However, Nginx compiled from the source code does not automatically create this script (it will tell you how to manually create it later ), now let's see how to stop the script before it is created.
You may have noticed the prompt "nginx pid file:"/usr/local/nginx/logs/nginx. pid "", you can check it at cat. It records the current nginx pid number, so we can stop nginx like this.
Sudo kill 'cat/usr/local/nginx/logs/nginx. pid'
Note: here we use reverse quotation marks (') instead of single quotation marks (').
Vi. Summary
This article describes how to use the source code on Ubuntu to compile and install nginx as needed, and then describes how to manually start and stop nginx, subsequent articles will introduce how to create an init script and how to plan and adjust the directory structure (sites-available and sites-enabled), and how to configure nginx to make it more powerful.
VII. Appendix: Compile-time options
(For the original article, refer:
Http://wiki.codemongers.com/NginxInstallOptions)
The configure script determines some features of the system, especially the nginx method for handling connections. Then, it creates the Makefile file.
Configure supports the following options:
1) Directory Properties
-- Prefix =<Path>-Nginx installation path. If not specified, the default value is/usr/local/nginx.
-- Sbin-path =<Path>-Nginx Executable File Installation path. It can only be specified during installation. If it is not specified, the default value is <prefix>/sbin/nginx.
-- Conf-path =<Path>-the default nginx. conf path is not specified under-c. If not specified, the default value is <prefix>/conf/nginx. conf.
-- Pid-path =<Path>-if no pid command is specified in nginx. conf, the default nginx. pid path is used. If not specified, the default value is <prefix>/logs/nginx. pid.
-- Lock-path =<Path>-nginx. lock file path. The default value is <prefix>/logs/nginx. lock.
-- Error-log-path =<Path>-the default error log path when no error_log command is specified in nginx. conf. If not specified, the default value is <prefix>/logs/error. log.
-- Http-log-path =<Path>-the default access log path when no access_log command is specified in nginx. conf. If not specified, the default value is <prefix>/logs/access. log.
-- User =<User>-if no user command is specified in nginx. conf, the default nginx user is used. If not specified, the default value is nobody.
-- Group =<Group>-the default group used by nginx when no user command is specified in nginx. conf. If not specified, the default value is nobody.
-- Builddir = DIR-Specify the compiled directory
2) Module
With-rtsig_module-Enable the rtsig Module
With-select_module Without-select_module-SELECT mode is allowed or not allowed. If configure does not find a more suitable mode, such as kqueue (sun OS), epoll (linux kenel 2.6 +), and rtsig (real-time signal) or/dev/poll (a select-like mode, the underlying implementation is basically the same as the SELECT, all adopt the Round Training Method) SELECT mode will be the default installation mode
With-poll_module Without-poll_module-Whether or not to enable the poll module. This module is enabled by default if a more suitable method such as kqueue, epoll, rtsig or/dev/poll is not discovered by configure.
With-http_ssl_module-Enable the http ssl module so that NGINX can support HTTPS requests. OPENSSL must be installed in this module, which is libssl On DEBIAN.
With-http_realip_module-Enable ngx_http_realip_module
With-http_addition_module-Enable ngx_http_addition_module
With-http_sub_module-Enable ngx_http_sub_module
With-http_dav_module-Enable ngx_http_dav_module
With-http_flv_module-Enable ngx_http_flv_module
With-http_stub_status_module-Enable the "server status" Page
Without-http_charset_module-Disable ngx_http_charset_module
Without-http_gzip_module-Disable ngx_http_gzip_module. zlib is required if ngx_http_gzip_module is enabled.
Without-http_ssi_module-Disable ngx_http_ssi_module
Without-http_userid_module-Disable ngx_http_userid_module
Without-http_access_module-Disable ngx_http_access_module
Without-http_auth_basic_module-Disable ngx_http_auth_basic_module
Without-http_autoindex_module-Disable ngx_http_autoindex_module
Without-http_geo_module-Disable ngx_http_geo_module
Without-http_map_module-Disable ngx_http_map_module
Without-http_referer_module-Disable ngx_http_referer_module
Without-http_rewrite_module-Disable ngx_http_rewrite_module. PCRE is required if ngx_http_rewrite_module is enabled.
Without-http_proxy_module-Disable ngx_http_proxy_module
Without-http_fastcgi_module-Disable ngx_http_fastcgi_module
Without-http_memcached_module-Disable ngx_http_memcached_module
Without-http_limit_zone_module-Disable ngx_http_limit_zone_module
Without-http_empty_gif_module-Disable ngx_http_empty_gif_module
Without-http_browser_module-Disable ngx_http_browser_module
Without-http_upstream_ip_hash_module-Disable ngx_http_upstream_ip_hash_module
With-http_perl_module-Enable ngx_http_perl_module
-- With-perl_modules_path = PATH-Specify the path of the perl Module
-- With-perl = PATH-Specify the path of the perl execution File
-- Http-log-path = PATH-Set path to the http access log
-- Http-client-body-temp-path = PATH-Set path to the http client request body temporary files
-- Http-proxy-temp-path = PATH-Set path to the http proxy temporary files
-- Http-fastcgi-temp-path = PATH-Set path to the http fastcgi temporary files
-- Without-http-Disable HTTP server
-- With-mail-Enable IMAP4/POP3/SMTP proxy Module
With-mail_ssl_module-Enable ngx_mail_ssl_module
-- With-cc = PATH-Specify the path of the C compiler.
-- With-cpp = PATH-Specify the path of the C Preprocessor
-- With-cc-opt = OPTIONS-Additional parameters which will be added to the variable CFLAGS. with the use of the system library PCRE in FreeBSD, it is necessary to indicate -- with-cc-opt = "-I/usr/local/include ". if we are using select () and it is necessary to increase the number of file descriptors, then this also can be assigned here: -- with-cc-opt = "-D FD_SETSIZE = 2048 ".
-- With-ld-opt = OPTIONS-Additional parameters passed to the linker. with the use of the system library PCRE in FreeBSD, it is necessary to indicate -- with-ld-opt = "-L/usr/local/lib ".
-- With-cpu-opt = CPU-For Specific CPU compilation, valid values include: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64
-- Without-pcre-Disable the use of the PCRE Library. The HTTP rewrite module is also disabled. The regular expression in the "location" configuration command also needs PCRE.
-- With-pcre = DIR-Specifies the path of the source code of the PCRE Library.
-- With-pcre-opt = OPTIONS-Set additional options for PCRE building.
-- With-md5 = DIR-Set path to md5 library sources.
-- With-md5-opt = OPTIONS-Set additional options for md5 building.
With-md5-asm-Use md5 receiver sources.
-- With-sha1 = DIR-Set path to sha1 library sources.
-- With-sha1-opt = OPTIONS-Set additional options for sha1 building.
With-sha1-asm-Use sha1 extends er sources.
-- With-zlib = DIR-Set path to zlib library sources.
-- With-zlib-opt = OPTIONS-Set additional options for zlib building.
-- With-zlib-asm = CPU-Use zlib assembler sources optimized for specified CPU, valid values are: pentium, pentiumpro
-- With-openssl = DIR-Set path to OpenSSL library sources
-- With-openssl-opt = OPTIONS-Set additional options for OpenSSL building
-- With-debug-Enable debugging logs
-- Add-module = PATH-Add in a third-party module found in directory PATH
++ ++ =