Questions tagged [nginx]

Nginx ("eNgine x") is a lightweight, high-performance HTTP server, reverse proxy, TCP stream proxy and mail proxy, released under a BSD-like license.

Nginx is a web server and mail proxy known for its high performance and small resource footprint. It is used in many places as a replacement to Apache and also as a front end server to static content or reverse proxying. Nginx is developed under a BSD-like license by Kazakhstani developer Igor Sysoev.

Nginx comes with diverse modules that enable it to perform various different tasks such as load balancing, URL rewriting, request rate limiting, content compression, raw TCP proxying and integration with tools like memcached or scripting languages like Lua.

Nginx is being used by some of the worlds busiest sites like WordPress, Sourceforge, Github and Reddit. Its market share has been raising from 7% in 2008 to over 30% as of June 2016 according to W3techs statistics.

After nine years of development, Nginx 1.0 stable was released on April 2011.

16419 questions
98
votes
8 answers

Properly setting up a "default" nginx server for https

I have several servers running on the same machine, some with http only, some with both http and https. There are several server blocks defined in separate files which are included from the main config file. I have set up a "default" server for…
Roar
97
votes
5 answers

Do you need separate IPv4 and IPv6 listen directives in nginx?

I've seen various config examples for handling dual-stack IPv4 and IPv6 virtual hosts on nginx. Many suggest this pattern: listen 80; listen [::]:80 ipv6only=on; As far as I can see, this achieves exactly the same thing as: listen [::]:80…
Synchro
  • 2,983
  • 5
  • 25
  • 35
96
votes
5 answers

Disable caching when serving static files with Nginx (for development)

We are using Nginx to serve static files on a development platform. As it is a development platform, we'd like to disable caching so that each change is propagated to the server. The configuration of the VHost is quite simple: server { server_name…
Olivier Chappe
  • 961
  • 1
  • 7
  • 4
96
votes
6 answers

How to force nginx to resolve DNS (of a dynamic hostname) everytime when doing proxy_pass?

I am using nginx/0.7.68, running on CentOS, with the following configuration: server { listen 80; server_name ***; index index.html index.htm index.php default.html default.htm default.php; location / { root …
xiamx
  • 1,152
  • 1
  • 8
  • 10
95
votes
5 answers

How to make a modification take affect without restarting nginx?

Apache has a graceful option which can scan for modification in http.conf without restarting Apache. What about nginx?
vps
  • 1,187
  • 3
  • 12
  • 12
94
votes
1 answer

How to use nested Nginx location blocks (prefixes vs. regex directives)?

I'm having trouble understanding nested locations in nginx. I have two locations with some configuration directives in common, so rather than repeat the directives, I'd prefer to repeat the URI using a regular-expression: location ~ /a|/b { …
Jayen
  • 1,827
  • 3
  • 16
  • 27
87
votes
4 answers

Nginx Redirect via Proxy, Rewrite and Preserve URL

In Nginx we have been trying to redirect a URL as follows: http://example.com/some/path -> http://192.168.1.24 where the user still sees the original URL in their browser. Once the user is redirected, say they click on the link to…
robjohncox
  • 1,025
  • 1
  • 8
  • 7
87
votes
4 answers

Nginx - root versus alias, for serving single files?

After many hours getting nginx to serve single files such as robots.txt (hint: clear your browser cache each time), I wound up with two different ways, one using the alias directive, and one using the root directive, like so: location /robots.txt {…
Cyclops
  • 1,139
  • 2
  • 9
  • 13
86
votes
2 answers

Why do I need nginx when I have uWSGI

There are many tutorials on how to configure nginx to cooperate with uWGSI when I want to deploy Django application. But why do I need nginx in this kit? uWSGI itself can serve WSGI Python applications, it can serve static files, it can also do…
user983447
  • 1,107
  • 1
  • 10
  • 10
78
votes
1 answer

What’s the difference between the “mainline” and “stable” branches of nginx?

There seem to be two active branches of the nginx web server: a “mainline” branch (currently 1.9.x) and a “stable” branch (currently 1.8.x). Can anyone provide an official source that describes the difference between these two branches and how one…
bdesham
  • 1,645
  • 4
  • 14
  • 22
78
votes
9 answers

How to restart Nginx on Mac OS X?

I just installed Nginx on Mac OS X (thanks http://www.kevinworthington.com/nginx-mac-os-snow-leopard-2-minutes/), but how do I restart Nginx on Mac OS X? Thanks!
Laura Brown
  • 813
  • 1
  • 7
  • 5
76
votes
10 answers

Remove "www" and redirect to "https" with nginx

I want to create a rule in nginx that does two things: Removes the "www." from the request URI Redirects to "https" if the request URI is "http" There are plenty of examples of how to do each of those things individually, but I can't figure out a…
Devin
  • 883
  • 1
  • 8
  • 8
75
votes
5 answers

Nginx redirect one path to another

I'm sure this has been asked before, but I can't find a solution that works. A website has switched CMS services, but has the same domain, how do I set up an nginx rewrite for a single page? E.g. Old…
SteveEdson
  • 1,479
  • 3
  • 12
  • 23
73
votes
4 answers

What is the difference between Nginx variables $host, $http_host, and $server_name?

What is the difference between the three Nginx variables $host, $http_host, and $server_name? I have a rewrite rule where I'm not sure which one I should be using: location = /vb/showthread.php { #…
Jeff Widman
  • 2,285
  • 3
  • 22
  • 20
73
votes
4 answers

nginx real_ip_header and X-Forwarded-For seems wrong

The wikipedia description of the HTTP header X-Forwarded-For is: X-Forwarded-For: client1, proxy1, proxy2, ... The nginx documentation for the directive real_ip_header reads, in part: This directive sets the name of the header used for…
Kirk Woll
  • 833
  • 1
  • 7
  • 7