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.

Filter by
Sorted by
Tagged with
10 votes
1 answer
6k views

How can I forward requests from my web server?

This is a Canonical Question about reverse proxies, how they work and how they are configured. How can I serve requests from a service on a different port or from a different server with the same ...
Gerald Schneider's user avatar
554 votes
11 answers
601k views

In Nginx, how can I rewrite all http requests to https while maintaining sub-domain?

I want to rewrite all http requests on my web server to be https requests, I started with the following: server { listen 80; location / { rewrite ^(.*) https://mysite.com$1 ...
MikeN's user avatar
  • 8,502
313 votes
5 answers
723k views

Nginx reverse proxy + URL rewrite

Nginx is running on port 80, and I'm using it to reverse proxy URLs with path /foo to port 3200 this way: location /foo { proxy_pass http://localhost:3200; ...
jeffreyveon's user avatar
  • 3,295
38 votes
5 answers
78k views

How to handle relative urls correctly with a nginx reverse proxy

Sure I'm not the first one that tried to serve a domain example.com from a example.net/bbb, but I haven't found a solution yet. My NGINX configuration follows the guidelines and looks something like ...
a.barbieri's user avatar
152 votes
13 answers
184k views

How to set up Nginx as a caching reverse proxy?

I heard recently that Nginx has added caching to its reverse proxy feature. I looked around but couldn't find much info about it. I want to set up Nginx as a caching reverse proxy in front of Apache/...
Continuation's user avatar
  • 3,130
89 votes
4 answers
342k views

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 ...
robjohncox's user avatar
  • 1,045
111 votes
6 answers
210k views

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 ...
xiamx's user avatar
  • 1,302
109 votes
10 answers
113k views

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 ...
user avatar
90 votes
5 answers
111k views

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's user avatar
  • 2,545
18 votes
1 answer
17k views

What is Apache's equivalent of Nginx's try_files?

In Nginx there is try_files, a config directive that "checks for the existence of files in order, and returns the first file that is found". I find it very neat to do this location ~* \.(gif|jpe?g|...
phunehehe's user avatar
  • 761
124 votes
16 answers
481k views

Nginx 1 FastCGI sent in stderr: “Primary script unknown”

My first time using Nginx, but I am more than familiar with Apache and Linux. I am using an existing project and when ever I am trying to see the index.php I get a 404 File not found. Here is the ...
We0's user avatar
  • 1,439
41 votes
2 answers
84k views

How to reduce number of sockets in TIME_WAIT?

Ubuntu Server 10.04.1 x86 I've got a machine with a FCGI HTTP service behind nginx, that serves a lot of small HTTP requests to a lot of different clients. (About 230 requests per second in the peak ...
Alexander Gladysh's user avatar
238 votes
7 answers
343k views

How to force or redirect to SSL in nginx?

I have a signup page on a subdomain like: https://signup.example.com It should only be accessible via HTTPS but I'm worried people might somehow stumble upon it via HTTP and get a 404. My html/...
Callmeed's user avatar
  • 2,725
82 votes
4 answers
124k views

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 ...
Kirk Woll's user avatar
  • 923
6 votes
1 answer
4k views

My browser will not display http://[sub.]example.com

When I go to http://sub.example.com in my browser I get a "connection refused" message or an "invalid certificate" error but I don't even want to connect over https. As far as I ...
Bob's user avatar
  • 5,983
3 votes
1 answer
4k views

nginx certbot certificate www and non-www

I haven't really wrapped my head around how to create (working) certificates using certbot for nginx. My sites-enables now look like this: First, a block for the www domain with SSL. All the SSL ...
Mattis Erngren's user avatar
233 votes
5 answers
255k views

nginx HTTPS serving with same config as HTTP

Is there a way to share configuration directives across two nginx server {} blocks? I'd like to avoid duplicating the rules, as my site's HTTPS and HTTP content are served with the exact same config. ...
ceejayoz's user avatar
  • 33.2k
152 votes
7 answers
408k views

Make nginx to pass hostname of the upstream when reverseproxying

I run several docker containers with hostnames: web1.local web2.local web3.local Routing to these done based on hostname by nginx. I have a proxy in front of this setup (on different machine ...
pavel_karoukin's user avatar
108 votes
4 answers
217k views

an upstream response is buffered to a temporary file

I have a rather large and slow (complex data, complex frontend) web application build in RoR and served by Puma with nginx as reverse proxy. Looking at the nginx error log, I see quite a few entries ...
ngw's user avatar
  • 1,291
80 votes
11 answers
71k views

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 ...
Devin's user avatar
  • 923
20 votes
1 answer
21k views

maintaining redirects in nginx from an external source

I am in the situation to give our marketing department the opportunity to maintain their redirects by their own. Until now, they passed the information to the IT department and we maintained it for ...
Sascha's user avatar
  • 538
11 votes
5 answers
60k views

Can't restart nginx, bind() failed (98: Address already in use)

I know this topic exists in various different forms, but I'm having trouble solving my problem. If I run service nginx restart, nginx fails with the following log: 2015/03/14 08:36:42 [emerg] 9400#0: ...
dallen's user avatar
  • 249
1 vote
1 answer
5k views

Why nginx internal redirect is not happening

I'm pretty sure I missed an obvious thing but it's driving me crazy, I need other eyeballs.. I got an application with plugins were sources are organized like: /app/plugins/foo/www/... that ...
Manuel VACELET's user avatar
172 votes
5 answers
322k views

How to remove the path with an nginx proxy_pass

I have a running web-application at http://example.com/, and want to "mount" another application, on a separate server on http://example.com/en. Upstream servers and proxy_pass seem to work, but for ...
berkes's user avatar
  • 2,285
121 votes
2 answers
292k views

How does try_files work?

I looked at the nginx documentation and it still confuses me utterly. How does try_files work? Here is what the documentation says: From NginxHttpCoreModule try_files syntax: try_files path1 ...
user avatar
44 votes
3 answers
169k views

nginx as reverse proxy with upstream SSL

I'm building a proxy for an internal API to allow clients to connect without having to have the self-signed certificates installed. Clients (built, owned and used only internally) will connect over ...
simonmaddox's user avatar
39 votes
3 answers
125k views

Nginx - How to redirect users with certain IP to special page

I run quite a big image gallery and there are 5 visitors that create an enormous amount of traffic by downloading the whole site every day using webcopiers. Those visitors have static IPs as it seems. ...
Alex's user avatar
  • 391
35 votes
5 answers
62k views

Nginx disable .htaccess and hidden files but allow .well-known directory

I have a Nginx server, and disabled hidden files in the nginx_vhost.conf ## Disable .htaccess and other hidden files location ~ /\. { deny all; access_log off; ...
Janghou's user avatar
  • 505
8 votes
2 answers
21k views

Nodejs Nginx error: (13: Permission denied) while connecting to upstream

I'm trying to run multiple Nodejs applications on Nginx server running on CentOS 7. I noticed that when I run a Nodejs app on some ports I get an 502 Bad Gateway error in the browser so I checked the ...
user1's user avatar
  • 181
6 votes
1 answer
4k views

How can I get around using alias in nginx?

Due to a long-standing bug in nginx I was advised to switch my alias directive with a root directive. Unfortunately this now breaks my static files, which are located in a different directory to my ...
Jonathan's user avatar
  • 1,319
5 votes
1 answer
10k views

Nginx + PHP-FPM URI alias and multiple php directories

I am trying to configure Nginx to host multiple PHP based apps in two different directories in the same domain. The outcome I'm trying to get to is: http://webserver.local/ > app served from /path/...
cpjones44's user avatar
  • 160
3 votes
1 answer
5k views

Nginx rewite rules 403 error

I am having trouble with converting .htaccess files to nginx. I have 3 .htaccess files. The first .htaccess file is located in the document root and is as follows: Options +FollowSymLinks ...
Adrian's user avatar
  • 67
112 votes
8 answers
197k views

Setting the "Expires" HTTP header for static content served from Nginx?

I'm using nginx to server my static content, is there a way that I can set the expires headers for every file that meets a specific rule? For example can I set the expires header for all files that ...
Unkwntech's user avatar
  • 1,759
81 votes
5 answers
86k views

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 ...
Sergio Tulentsev's user avatar
67 votes
2 answers
109k views

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/...
Niels's user avatar
  • 831
61 votes
4 answers
166k views

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:...
bwizzy's user avatar
  • 1,295
50 votes
3 answers
77k views

Use HTTP/2.0 between nginx reverse-proxy and backend webserver

I use nginx as a reverse-ssl-proxy in front of a backend webserver that is capable of doing HTTP/2.0. I noticed that nginx proxies the requests to the backend server via HTTP/1.1 rather than HTTP/2.0....
S1lentSt0rm's user avatar
  • 1,079
48 votes
3 answers
123k views

Can nginx location blocks match a URL query string?

Can nginx location blocks match a URL query string? For example, what location block might match HTTP GET request GET /git/sample-repository/info/refs?service=git-receive-pack HTTP/1.1
Derek Mahar's user avatar
42 votes
2 answers
38k views

How to rate-limit in nginx, but including/excluding certain IP addresses?

I'm able to use limit_req to rate-limit all requests to my server. However I'd like to remove the rate restriction for certain IP addresses (i.e. whitelist) and use a different rate restriction for ...
Jason Cohen's user avatar
  • 1,127
23 votes
6 answers
20k views

Nginx. How do I reject request to unlisted ssl virtual server?

I have a wildcard SSL certificate and several subdomains on the same ip. Now I want my nginx to handle only mentioned server names and drop connection for others so that it'd look like nginx is not ...
andbi's user avatar
  • 353
21 votes
2 answers
79k views

nginx rewrite for an url with parameters

I have an URL of this type: http://www.example.com/?param1=val1&param2=&param3=val3&param4=val4&param5=val5 And I want to redirect it to this one: http://www.example.com/newparam/...
David Morales's user avatar
17 votes
2 answers
63k views

Nginx: how to set host header to the server chosen (load balancing)

I have a site that works as load balancer. Site A. I have other sites that only can have one domain. So if i just redirect to them it says host name not found. So if i manually set header to ...
Muhammad Umer's user avatar
6 votes
2 answers
12k views

Copy and deliver a request to another nginx server for real traffic testing

I have a Flask web service which runs on uwsgi+nginx and it works well. I have another development version of the service which runs on another server. It also runs on uwsgi+nginx. What I want to do ...
Younggun Kim's user avatar
5 votes
1 answer
5k views

Best way to set up permissions with nginx + php-fpm on shared hosting?

I'm running a shared hosting server with nginx and php-fpm on Debian. Everything works fine, php-fpm has separate pools for each users running as separate users and they each have their own socks. ...
dBi's user avatar
  • 75
4 votes
2 answers
1k views

nginx location pathing issue

I've got a pretty much default sites-enabled set up in my nginx on debian squeeze and i'm now trying to get it to serve up my munin graphs on myhost/munin/ Heres the location i've added to the config ...
Michael Jefferys's user avatar
2 votes
1 answer
1k views

Varnish cache with Nginx SSL termination

How can I use varnish cache with nginx SSL termination for my SSL-Only (Https only) website? I use ubuntu 18.04 and I am currently running a wordpress site on my server.
Rahul Biswas's user avatar
0 votes
1 answer
1k views

Deploying a static site on AWS EC2/nginx: what am I doing wrong?

I set up a micro instance (Ubuntu, 32 bit) and assigned an elastic IP (23.23.245.104) Public DNS: ec2-23-23-245-104.compute-1.amazonaws.com I successfully ssh'ed to the machine and installed nginx. ...
Alex's user avatar
  • 139
374 votes
30 answers
510k views

How can I use environment variables in Nginx.conf

I have a docker container running Nginx, that links to another docker container. The host name and IP address of the second container is loaded into the Nginx container as environment variables on ...
Hugo Rodger-Brown's user avatar
258 votes
8 answers
1.0m views

How do I add Access-Control-Allow-Origin in NGINX?

How do I set the Access-Control-Allow-Origin header so I can use web-fonts from my subdomain on my main domain? Notes: You'll find examples of this and other headers for most HTTP servers in the ...
Chris McKee's user avatar
  • 3,539
131 votes
4 answers
384k views

Nginx: How do I forward an HTTP request to another port?

What I want to do is: When someone visits http://localhost/route/abc the server responds exactly the same as http://localhost:9000/abc Now I configure my Nginx server like this: location /route { ...
WoooHaaaa's user avatar
  • 1,675

1
2 3 4 5
22