Websites with Nginx on Fedora 14

Select distribution:
Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Deprecated

This guide has been deprecated and is no longer being maintained.

Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

Nginx is a lightweight and high performance HTTP web server designed with the purpose of delivering large amounts of static content quickly and with efficient use of system resources. In contrast to the Apache HTTP server that uses a threaded or process-oriented approach to handling requests, nginx uses an asynchronous event-driven model which can provide more predictable performance under load.

It is assumed that you have followed our Setting Up and Securing a Compute Instance guide. If you are new to Linux server administration, you may be interested in our introduction to Linux concepts guide, beginner’s guide and administration basics guide. You should be logged into your Linode as the “root” user before proceeding.

Set the Hostname

Before you begin installing and configuring the components described in this guide, please make sure you’ve followed our instructions for setting your hostname. Issue the following commands to make sure it is set properly:

hostname
hostname -f

The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).

Install nginx from EPEL Packages

Nginx is included in the Fedora software repositories. While using this method to install nginx will leave you with a working web server, it is not the preferred method for installing nginx. Nevertheless, if you want to install in this manner, use the process that follows.

The following sequence of commands first ensures that your system’s package databases and installed programs are up to date and then installs the nginx web server:

yum update
yum install nginx

Once finished, start nginx the following command:

/etc/init.d/nginx start

You can now continue with the configuration of nginx. Installing nginx in this manner will allow you to rely on the Fedora package maintainers to provide quality control, testing, and security updates to ensure that you’re running the best possible version of the software. However, the packages provided by the Fedora project may not track the latest development of the nginx server and do not allow you to enable certain nginx options at compile time. Given the rapid development of nginx and variances between recent versions, installing from distribution packages is not ideal for many users. Continue to the next section to install nginx directly from source.

Install nginx from the Source Distribution

Prerequisites

Because of the rapid development of the nginx web server and recent changes to the interface, many users of nginx compile their version of the software from sources provided by the nginx developers. Additional benefits include the ability to configure nginx to support additional third party modules and options which much be set at compile time.

Begin by ensuring that your system’s package database and installed programs are up to date by issuing the following command:

yum update

You will also need to install several dependent package before proceeding with nginx installation. Issue the following command:

yum install zlib-devel wget openssl-devel pcre pcre-devel sudo gcc make autoconf automake

At this point you can continue with the compilation and installation of nginx.

Download and Compile nginx

The source files and binaries will be downloaded in the /opt/ directory of the file system in this example. Issue the following sequence of commands to enter this directory, download the required files, and extract the source files from the archive. Be sure to check the nginx download page for the current version, changing the wget command below if necessary.

cd /opt/
wget http://nginx.org/download/nginx-1.0.0.tar.gz
tar -zxvf nginx-1.0.0.tar.gz
cd /opt/nginx-1.0.0

Now you can compile the nginx server. If you want to enable third-party nginx modules, append options to ./configure at this juncture. Issue the following command to configure the build options:

./configure --prefix=/opt/nginx --user=nginx --group=nginx --with-http_ssl_module

When the configuration process completes successfully, you will see the following output:

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1 library is not used
  + using system zlib library

  nginx path prefix: "/opt/nginx"
  nginx binary file: "/opt/nginx/sbin/nginx"
  nginx configuration prefix: "/opt/nginx/conf"
  nginx configuration file: "/opt/nginx/conf/nginx.conf"
  nginx pid file: "/opt/nginx/logs/nginx.pid"
  nginx error log file: "/opt/nginx/logs/error.log"
  nginx http access log file: "/opt/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"

To build and install nginx with the above configuration, use the following command sequence:

make
make install

You will also need to create a user and group for nginx, issue the following command:

useradd -M -r --shell /bin/bash --home-dir /opt/nginx nginx

Nginx is now installed in /opt/nginx.

Monitor for Software Updates and Security Notices

When running software compiled or installed directly from sources provided by upstream developers, you are responsible for monitoring updates, bug fixes, and security issues. After becoming aware of releases and potential issues, update your software to resolve flaws and prevent possible system compromise. Monitoring releases and maintaining up to date versions of all software is crucial for the security and integrity of a system.

Please follow the announcements, lists, and RSS feeds on the following pages to ensure that you are aware of all updates to the software and can upgrade appropriately or apply patches and recompile as needed:

When upstream sources offer new releases, repeat the instructions for installing nginx, spawn-fcgi, and uWSGI, and recompile your software when needed. These practices are crucial for the ongoing security and functioning of your system.

Create an Init Script to manage nginx

Before you begin to use the nginx server, you must create a means of controlling it. You can create an “init script” using this example to control nginx. Issue the following commands to download the file, change the execution mode, and set the system to initialize nginx on boot:

wget -O init-rpm.sh http://www.linode.com/docs/assets/663-init-rpm.sh
mv init-rpm.sh /etc/rc.d/init.d/nginx
chmod +x /etc/rc.d/init.d/nginx
chkconfig --add nginx
chkconfig --level 2345 nginx on

You can now start, stop, and restart nginx just like any other server daemon. For example, to start the server, issue the following command:

/etc/init.d/nginx start

Congratulations! You now have a running and fully functional HTTP server powered by the nginx web server. Continue reading our introduction to basic nginx configuration for more information about using and setting up the web server.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.