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
72
votes
1 answer

Nginx - Meaning of the ~ (tilde) in the location block of the nginx.conf?

What is the meaning of the tilde after the location block in the nginx configuration? for example location ~ ^/download/(.*)$ { alias /home/website/files/$1; } What is the difference between with and without the "~" ?
mahen3d
  • 3,905
  • 12
  • 34
  • 55
70
votes
11 answers

How can I create a location in nginx that works with AND without a trailing slash?

Right now I have this config: location ~ ^/phpmyadmin/(.*)$ { alias /home/phpmyadmin/$1; } However, if I visit www.mysite.com/phpmyadmin (note the lack of trailing slash), it won't find what I'm looking for a 404. I assume because I don't…
Rob
  • 2,303
  • 9
  • 31
  • 50
68
votes
3 answers

nginx: Log complete request / response with all headers?

We have an application server that sometimes hangs. We suspect it is due to a bad request from a client. Can nginx log the complete request/response (like fiddler captures) to files, so we can see the requests that were sent before the hang? (We…
68
votes
5 answers

Dump nginx config from running process?

Apparently, I shouldn't have spent sleepless night trying to debug an application. I wanted to restart my nginx and discovered that its config file is empty. I don't remember truncating it, but fat fingers and reduced attention probably played their…
Sergio Tulentsev
  • 783
  • 1
  • 8
  • 9
68
votes
2 answers

nginx url rewriting: difference between break and last

I don't understand the difference between break and last (flags of rewrite). The documentation is rather abstruse. I've tried to switch between the two in some of my configs, but I couldn't spot any difference in behavior. Can someone please explain…
user39883
67
votes
3 answers

Is the PHP option 'cgi.fix_pathinfo' really dangerous with Nginx + PHP-FPM?

There has been a lot of talking about a security issue relative to the cgi.fix_pathinfo PHP option used with Nginx (usually PHP-FPM, fast CGI). As a result, the default nginx configuration file used to say: # NOTE: You should have…
Totor
  • 2,876
  • 3
  • 22
  • 31
63
votes
4 answers

Suspicious symbols on nginx config

I have the following nginx config, e.g. server { listen 80; server_name example.com allow 127.0.0.0/8; When I restart, it warn me: Restarting nginx: nginx: [warn] server name "127.0.0.0/8" has suspicious symbols in…
Ryan
  • 5,341
  • 21
  • 71
  • 87
62
votes
2 answers

Nginx location regex doesn't work with proxy pass

I'm trying to get these 2 location directives working in Nginx but I'm getting some errors back when booting Nginx. location ~ ^/smx/(test|production) { proxy_pass http://localhost:8181/cxf; } location ~ ^/es/(test|production)…
Niels
  • 771
  • 2
  • 8
  • 8
60
votes
12 answers

104: Connection reset by peer while reading response header from upstream (Nginx)

I have a server which was working ok until 3rd Oct 2013 at 10:50am when it began to intermittently return "502 Bad Gateway" errors to the client. Approximately 4 out of 5 browser requests succeed but about 1 in 5 fail with a 502. The nginx error log…
Nigel Alderton
  • 942
  • 3
  • 9
  • 18
59
votes
4 answers

How to use nginx to proxy to a host requiring authentication?

How can I setup an nginx proxy_pass directive that will also include HTTP Basic authentication information sent to the proxy host? This is an example of the URL I need to proxy to: http://username:password@192.168.0.5/export?uuid=1234567890 The…
bwizzy
  • 1,265
  • 4
  • 14
  • 17
57
votes
2 answers

nginx set variable in location

I am trying to optimize my nginx configs, so it would be possible to set one variable, and all location paths would update automatically. I have four lines in question: server_name php.domain.com; root /srv/web/vhosts/php/web; error_log…
Bogdan Kuštan
  • 673
  • 1
  • 5
  • 6
57
votes
4 answers

best way to debug nginx rewrite rules in config file?

I have a bunch of rewrite rules that I have to port from apache to nginx. It's a rather painful process because I'm not able to see if my rewrite rules and "if" conditions are working as I want them to. Apache did have debugging for its rewrite…
Jiho Kang
  • 967
  • 2
  • 9
  • 8
55
votes
5 answers

Optimal value for Nginx worker_connections

Nginx worker_connections "sets the maximum number of simultaneous connections that can be opened by a worker process. This number includes all connections (e.g. connections with proxied servers, among others), not only connections with clients.…
Aarti
  • 629
  • 1
  • 7
  • 6
55
votes
4 answers

How do I change the NGINX user?

I have a PHP script that creates a directory and outputs an image to the directory. This was working just fine under Apache but we recently decided to switch to NGINX to make more use of our limited RAM. I'm using the PHP mkdir() command to create…
David
  • 745
  • 3
  • 7
  • 10
55
votes
2 answers

How can I configure nginx locations to share common configuration options?

How can i configure a shared config block for a set of locations? location / { proxy_pass http://127.0.0.1:9000/; proxy_redirect off; proxy_set_header Host $http_host; …
netbrain
  • 703
  • 1
  • 6
  • 11