Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

nginx 1.4 on Red Hat Enterprise Linux 7

October 22, 2014
Joe Orton
Related topics:
Linux
Related products:
Red Hat Enterprise Linux

Share:

    In this post I'm going to talk about using the nginx web server on Red Hat Enterprise Linux 7.  nginx 1.4 was added as a "Tech Preview" in the v1.1 release of Red Hat Software Collections.

    nginx

    Starting from a freshly kickstarted RHEL7 VM, here's how to get going:

    [root@virt-el7scratch ~]# subscription-manager repos --enable rhel-server-rhscl-7-rpms
    Repo 'rhel-server-rhscl-7-rpms' is enabled for this system.

    This enables the Red Hat Software Collections repository in the yum configuration, which is available with most RHEL entitlements.

    [root@virt-el7scratch ~]# yum install nginx14
    ...
    Installed:
      nginx14.x86_64 0:1.1-3.el7
    Dependency Installed:
      gd.x86_64 0:2.0.35-26.el7 nginx14-nginx.x86_64 1:1.4.4-10.el7
      nginx14-runtime.x86_64 0:1.1-3.el7 scl-utils.x86_64 0:20130529-5.el7
    
    Complete!

    That has installed the nginx 1.4 software collection. Like all SCLs, nginx ends up in /opt/rh - specifically /opt/rh/nginx14, but we have a systemd unit file in the correct system location for integration:

    [root@virt-el7scratch ~]# systemctl start nginx14-nginx
    [root@virt-el7scratch ~]# systemctl status nginx14-nginx
    nginx14-nginx.service - The nginx HTTP and reverse proxy server
    Loaded: loaded (/usr/lib/systemd/system/nginx14-nginx.service; disabled)
    Active: active (running) since Thu 2014-10-09 12:28:39 BST; 47s ago
    Process: 10346 ExecStart=/opt/rh/nginx14/root/usr/sbin/nginx (code=exited, status=0/SUCCESS)
    Process: 10345 ExecStartPre=/opt/rh/nginx14/root/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
    Main PID: 10348 (nginx)
    CGroup: /system.slice/nginx14-nginx.service
            ├─10348 nginx: master process /opt/rh/nginx14/root/usr/sbin/nginx
            └─10350 nginx: worker process
    ...
    

    The nginx daemon is running out of the SCL like any other systemd service. Now, I could demo a static page load or a proxy configuration here... but dynamic languages are more fun! Instead I'll pull in another software collection and demo PHP:

    To use PHP from nginx we use FastCGI. So, I'll pull in the FastCGI Process Manager package, "FPM" from the PHP 5.5 software collection, and start that daemon:

    [root@virt-el7scratch ~]# yum install php55-php-fpm
    ...
    Installed:
      php55-php-fpm.x86_64 0:5.5.6-10.el7
    
    Dependency Installed:
      libzip.x86_64 0:0.10.1-8.el7 php55-php-cli.x86_64 0:5.5.6-10.el7
      php55-php-common.x86_64 0:5.5.6-10.el7 php55-php-pear.noarch 1:1.9.4-10.el7
      php55-php-pecl-jsonc.x86_64 0:1.3.5-1.el7 php55-php-process.x86_64 0:5.5.6-10.el7
      php55-php-xml.x86_64 0:5.5.6-10.el7 php55-runtime.x86_64 0:1.1-7.el7
    
    [root@virt-el7scratch ~]# systemctl start php55-php-fpm
    [root@virt-el7scratch ~]# systemctl status php55-php-fpm
    php55-php-fpm.service - The PHP FastCGI Process Manager
      Loaded: loaded (/usr/lib/systemd/system/php55-php-fpm.service; disabled)
      Active: active (running) since Thu 2014-10-09 12:45:00 BST; 1s ago
      Main PID: 10634 (php-fpm)
      Status: "Ready to handle connections"
      CGroup: /system.slice/php55-php-fpm.service
              ├─10634 php-fpm: master process (/opt/rh/php55/root/etc/php-fpm.conf)
              ├─10635 php-fpm: pool www
    ...

    To configure nginx to use FastCGI, we edit the /opt/rh/nginx14/root/etc/nginx/nginx.conf configuration file. There is already a commented-out example for use of FastCGI in the default "http" (port 80) server stanza. Uncomment it and change the SCRIPT_FILENAME parameter to pull straight out of the document root:

         location ~ .php$ {
                  root html;
                  fastcgi_pass 127.0.0.1:9000;
                  fastcgi_index index.php;
                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                  include fastcgi_params;
              }

    And that's all the configuration that is required! Reload the daemon, and we're off:

    [root@virt-el7scratch ~]# systemctl reload nginx14-nginx
    [root@virt-el7scratch ~]# echo '<?php echo "Hello, worldn"; ?>' > /opt/rh/nginx14/root/usr/share/nginx/html/hello.php
    [root@virt-el7scratch ~]# curl http://localhost/hello.php
    Hello, world
    

    Note that the default document root for nginx is inside the SCL, though this can be changed by amending the "root" directive in nginx.conf.

    Last updated: November 2, 2023

    Recent Posts

    • Why Models-as-a-Service architecture is ideal for AI models

    • How to run MicroShift as a container using MINC

    • OpenShift 4.19 brings a unified console for developers and admins

    • 3 steps to secure network segmentation with Ansible and AWS

    • Integrate vLLM inference on macOS/iOS using OpenAI APIs

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue