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.
1,063
questions
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 ...
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 ...
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;
...
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 ...
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/...
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 ...
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 ...
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 ...
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 {
...
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|...
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 ...
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 ...
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/...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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: ...
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 ...
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 ...
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 ...
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 ...
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. ...
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;
...
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 ...
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 ...
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/...
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
...
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 ...
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 ...
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/...
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:...
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....
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
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 ...
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 ...
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¶m2=¶m3=val3¶m4=val4¶m5=val5
And I want to redirect it to this one:
http://www.example.com/newparam/...
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 ...
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 ...
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.
...
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
...
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.
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.
...
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 ...
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 ...
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 {
...