options available while installing nginx

Sarath Pillai's picture
Nginx installation options

In the previous two posts about nginx.. how is nginx different from apache, How to install nginx in rhel and centos we have discussed the difference between apache and nginx, and also learned how to install nginx, with basic options and modules enabled.

But there are some advanced options which we need to understand to install nginx in a more efficient manner. We did have a look at the following options we supplied to the ./configure command.

--prefix,--pid-path,--http-log-path,--without-http_rewrite_module,--without-http_gzip_module.

from the above options available in nginx installation that we learned from the previous post, some are modules(--without-http_rewrite_module,--without-http_gzip_module), and the remaining are simple path locations for various things like, installation directory,process ip path,log file path etc.

There are lot number of options available in nginx while installing, we will have a look at some of the interesting options,for modules and for path directives here.

--conf-path= this option can be used to seperatly specify the main config file path in the nginx installation. By default (installing without this option) this file will be under the location "<prefix>/conf/nginx.conf". In our installation during our previous post, the config file location is "/home/sarath/conf" because we kept our prefix as "/home/sarath"

--error-log-path= this option is used to specify the error log file path, just like we specified the main log file path with the option "--http-log-path". by default (installing without this option) this error log file goes into "<prefix>/logs/error.log". So in our case it was "/home/sarath/logs/error.log"

--lock-path= this option is used for specifying the path for the pid lock file. (nginx uses this lock file to confirm, that only one nginx application is running on the machine.) By default (installing without this option) this lock file goes into the path "<prefix>/logs/nginx.lock."

--with-perl_modules_path: this option needs to be added while installing nginx if you need additional perl modules, thats useful in nginx. You can specify your perl modules path directory with this option.

--with-perl= this specifies the perl binary file path, this can be located using whereis command in linux as shown below.

[root@slashroot ~]# whereis perl
perl: /usr/bin/perl /usr/share/man/man1/perl.1.gz

 

in most cased the perl binary file is located at /usr/bin/perl (as in our case). This option enables the capability to execute perl scripts.

--http-client-body-temp-path: this option can be used to specify the directory where temporary files generated by the client requests will be saved.

--user= this option will specify the default user with which the nginx worker process will be started. the nginx process will use this option only if incase you did not mention the user name in the nginx config file.

--group=: this is same as the above, but here with this option we will specify the group with which the nginx worker process will run.

Note:  Please remember to add permission to the user and group for reading and writing to the nginx files. In our previous installation as shown in the previous post, we have not given permission to any other user to the nginx prefix directory, and nginx will only start by root user.

 

Lets have a look at some of the modules that can be enabled while installing nginx

--with-http_ssl_module: this option enabled the ssl module used to server https connections.

--with-http_realip_module: by enabling this module nginx will be able to detect the real ip address from the request, by reading the headers of the packet.

--with-http_xslt_module: this module is used to translate and apply the XSL(EXtensible Stylesheet Language used to give styling to xml documents, its similar to css for html) content to XML documents.

--with-http_geoip_module: this module can be used to detect geographical locations of ip address using maxmind databse.libgeoip should be installed on the machine for this module to work properly.

--with-http_flv_module: this module enables the ability to fetch data from a .flv file or flash video file.

--with-http_image_filter_module: this module will add the functionality to edit or modify images and to apply the changes to the images edited of modified. But for enabling this module libgd library is required to be already installed on the machine

--with-ipv6: this enabled ip version 6 support into nginx while installing.

--with-debug: this module will help debugging easier as enabling this will start logging debugging information.

--with-http_stub_status_module: this module will enable nginx to supply some status about itself. this will show details and information like number of open connections, number of connections accepted and handled by nginx etc.

Now for configuring a simple http web server serving http and https connections, can be installed with just the below options.

./configure --user=www-data --group=www-data --with-http_ssl_module --with-http_realip_module

We need to give permissions to the user "www-data" and "www-data" group to the nginx directory.

One thing we need to understand is that if you install your nginx as shown below.

 ./configure --user=www-data --group=www-data

 

You already need to have the user and group www-data in your machine. because the nginx master process will start as root and the worker process which accepts connections will start as the user www-data. So the option --user explained above will be the user through which the nginx worker process will be running.

And this --user option is only used when there is no user specified in the nginx.conf file. If a user is specified in the config that user is used rather than this one specified with --user.

Now if nginx is installed without the --prefix option then it by default gets installed in /usr/local/nginx.

And you can start the nginx process with /usr/local/nginx/sbin/nginx command.

[root@slashroot ~]# /usr/local/nginx/sbin/nginx

Now lets check the number of worker process and master process with ps command.

[root@slashroot ~]# ps aux | grep nginx
root     16802  0.0  0.0   2460   440 ?        Ss   08:22   0:00 nginx: master process /usr/local/nginx/sbin/nginx
www-data 16803  0.0  0.1   2632   808 ?        S    08:22   0:00 nginx: worker process
root     16839  0.0  0.1   3912   672 pts/1    R+   08:23   0:00 grep nginx

and you can clearly see from the above result of the ps command that the nginx master process is started by root and worker process is started by www-data user.

there are some options in the /usr/local/nginx/sbin/nginx command which can be found by running the below command.

[root@slashroot ~]# /usr/local/nginx/sbin/nginx -h
nginx version: nginx/1.2.4
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
 
Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

Nginx configuration test can be done by the following command.

[root@slashroot ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

-V option available in the nginx binary is a handy option because it will show you the options that were used with configure command while installing nginx.

 

[root@slashroot ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.2.4
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-44)
configure arguments: --user=www-data --group=www-data --without-http_rewrite_module --without-http_gzip_module

In the next post will will create a init script for nginx service, and will configure nginx a little more.

Thank You..hope you guys enjoyed the post..!!

Rate this article: 
Average: 3.1 (19 votes)

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.