Nginx
  • 20 Jun 2024
  • 2 Minutes to read
  • Contributors
  • Dark
    Light
  • PDF

Nginx

  • Dark
    Light
  • PDF

Article summary

Nginx

This guide will show you how to integrate Prerender into your Nginx webserver. It includes a video tutorial and a comprehensive written guide, covering all major use cases for Nginx.

All example configs are available on this GitHub Link below.
View source on GitHub.

View the Nginx config here.

Nginx use case

To determine the appropriate Nginx Prerender integration, you need to consider your usage of Nginx. Below is a list of the most common use cases along with their corresponding GitHub links. Further down, you'll find video and text guides with corresponding titles.

Nginx use cases:

Single Page Application

Video Guide:

Prerender token

The location of the Prerender token has changed. You can find it under the Security and Access menu under Prerender Token.

Text guide:

  1. Open the Nginx Single Page Application code on our GitHub repository.
  2. It is recomended to make a backup from the Nginx config file.
  3. Add the map{...} sections from Github under your http{...} blocks in the config file.
    image.png
  4. Add the following code section to your location / {..} block
            if ($prerender = 1) {
                rewrite (.*) /prerenderio last;
            }

image.png
5. Add the location /prerenderio {...} block to your server block under the location / {..} block.
image.png
6. Replace the YOUR_TOKEN place holder with your Prerender.io Token from the Security and Access menu.
7. Run a Nginx config test and restart it if successfull.

PHP Application

Video guide:

Prerender token

The location of the Prerender token has changed. You can find it under the Security and Access menu under Prerender Token.

Text guide:

  1. Open the Nginx PHP application code on our GitHub repository.
  2. It is recomended to make a backup from the Nginx config file.
  3. Add the map{...} sections from Github in fron of the server block in the config file.
    image.png
  4. Add the following code section to your location / {..} block
        location / {
            if ($prerender = 1) {
                rewrite (.*) /prerenderio last;
            }
            rewrite (.*) /index.php$1 last;
        }

image.png

  1. Add the location /prerenderio {...} block to your server block under the location / {..} block.
    image.png
  2. Replace the YOUR_TOKEN place holder with your Prerender.io Token from the Security and Access menu.
  3. Add the following if statement in your ~ [^/].php(/|$) location block:
            if ($prerender = 1) {
                rewrite (.*) /prerenderio last;
            }

image.png

  1. Run a Nginx config test and restart it if successfull.

Reverse proxy

Video guide:

Prerender token

The location of the Prerender token has changed. You can find it under the Security and Access menu under Prerender Token.

Text guide:

  1. Open the Nginx Reverse proxy code on our GitHub repository.
  2. It is recomended to make a backup from the Nginx config file.
  3. Add the map{...} sections from Github under your http{...} blocks in the config file.
    image.png
  4. Add the following code section to your location / {..} block
            if ($prerender = 1) {
                rewrite (.*) /prerenderio last;
            }

image.png
5. Add the location /prerenderio {...} block to your server block under the location / {..} block.
image.png
6. Replace the YOUR_TOKEN place holder with your Prerender.io Token from the Security and Access menu.
7. Run a Nginx config test and restart it if successfull.


Was this article helpful?