280
votes
Is it possible to make Nginx listen to different ports?
You can also do the following:
server {
listen 80;
listen 8000;
server_name example.org;
root /var/www/;
}
190
votes
How can I use environment variables in Nginx.conf
From the official Nginx docker file:
Using environment variables in nginx configuration:
Out-of-the-box, Nginx doesn't support using environment variables
inside most configuration blocks.
...
145
votes
Nginx reverse proxy + URL rewrite
The absolute most correct way and best practice is usually as follows:
location /foo/ {
proxy_pass http://localhost:3200/; # note the trailing slash!
}
Note the dire importance of the trailing ...
141
votes
Accepted
How to disable timeout for nginx?
It may not be possible to disable it at all, yet a feasible workaround is to increase the execution time. On a nginx tutorial site, it was written:
If you want to increase time-limit for all-sites ...
126
votes
"413 Request Entity Too Large" in Nginx with "client_max_body_size" set
Modify NGINX Configuration File
sudo nano /etc/nginx/nginx.conf
Search for this variable: client_max_body_size. If you find it, just increase its size to 100M, for example. If it doesn’t exist, then ...
107
votes
How can I use environment variables in Nginx.conf
The official nginx image recommends using envsubst, but as pointed out by others it will replace also $host and other variables, which is not desirable. But fortunately envsubst can take as a ...
95
votes
How to set robots.txt globally in nginx for all virtual hosts
You can set the contents of the robots.txt file directly in the nginx config:
location = /robots.txt { return 200 "User-agent: *\nDisallow: /\n"; }
It is also possible to add the correct ...
93
votes
Accepted
Lets Encrypt with an nginx reverse proxy
Yes, you can have nginx proxy requests to HTTP servers, and then itself respond to clients over HTTPS. When doing this, you will want to be sure that the nginx<->proxy connect is unlikely to be ...
93
votes
Accepted
For Server-Sent Events (SSE) what Nginx proxy configuration is appropriate?
Long-running connection
Server-Sent Events (SSE) are a long-running HTTP connection**, so for starters we need this:
proxy_http_version 1.1;
proxy_set_header Connection "";
NOTE: TCP ...
92
votes
nginx url rewriting: difference between break and last
OP preferred an example. Also, what @minaev wrote, was only a part of the story! So, here we go...
Example 1: No (break or last) flags
server {
server_name example.com;
root 'path/to/somewhere'...
89
votes
How to automatically restart Nginx when it goes down
It is a feature of SystemD. Override existing unit file for NGINX by running systemctl edit nginx then paste in:
[Service]
Restart=always
Save.
If NGINX is down due to, e.g. the OOM killer, it will ...
84
votes
Accepted
Site is accessible by domain in all browsers but Chrome
Your problem is because you are using a .dev domain.
The entire .dev top-level domain (TLD) is on the HSTS preload list and that means you must access it using HTTPS. According to your nginx config ...
80
votes
Difference in sites-available vs sites-enabled vs conf.d directories (Nginx)?
What's Going On?
You must be using Debian or Ubuntu, since the evil sites-available / sites-enabled logic is not used by the upstream packaging of nginx from http://nginx.org/packages/.
In either case,...
74
votes
Nginx 1 FastCGI sent in stderr: “Primary script unknown”
It's not always that the SCRIPT_FILENAME is wrong.
It may also be PHP is running as the wrong user/group.
This example is specific to Mac OS X, which in my experience is the most troublesome to setup ...
74
votes
How to totally remove a certbot-created SSL certificate?
Yes, certbot can help you clean up.
sudo certbot certificates
will list what certbot thinks you have installed
sudo certbot delete
will allow you to interactively remove and clean up unwanted / ...
74
votes
Setting ssl_prefer_server_ciphers directive in nginx config
When ssl_prefer_server_ciphers is set to on, the web server owner can control which ciphers are available.
The reason why this control was preferred is old and insecure ciphers that were available in ...
73
votes
Optimal value for Nginx worker_connections
Let's take the pragmatic approach.
All these limits are things that were hardcoded and designed in the past century when hardware was slow and expensive. We're in 2016 now, an average wall-mart ...
69
votes
How can I use environment variables in Nginx.conf
envsubstr is handled automatically by the nginx image now.
From the docs:
Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But this image has a function, ...
66
votes
Accepted
How to reverse proxy to different places depending on subdomain in Nginx?
Unless I completely misread your question: You simply set up server blocks for each sub-domain and the define the correct reverse proxy for the root of that subdomain i.e. something along the lines ...
66
votes
Accepted
nginx: [emerg] "stream" directive is not allowed here
stream needs to be on the same level as http block so like
http { foo }
stream { bar }
My guess is your include for /etc/nginx/conf.d/*.conf is located in the http {} block and not outside of it. ...
63
votes
Accepted
Can nginx location blocks match a URL query string?
Can nginx location blocks match a URL query string?
Short answer: No.
Long answer: There is a workaround if we have only a handful of such location blocks.
Here's a sample workaround for 3 location ...
63
votes
Accepted
unknown directive "stream" in /etc/nginx/nginx.conf:86
The stream module is being added as dynamic, as per:
--with-stream=dynamic
You need it to be 'static' - so load the module directly. To do so, add the following at the very top of your nginx.conf:
...
59
votes
Accepted
How to handle relative urls correctly with a nginx reverse proxy
The problem is basically that using a proxy_pass directive won't rewrite HTML code and therefor relative URL's to for instance a img src="/assets/image.png" won't magically change to img src="/bbb/...
57
votes
Can I hide all server / os info?
If you have installed nginx using apt-get in Debian or Ubuntu, you might need to install the package nginx-extras to set or clear "Server" header
Once this is done, you can add the lines below in ...
53
votes
How to reply with 200 from Nginx, without serving a file?
If you want to return a formatted HTML text, without serving a HTML file:
location / {
default_type text/html;
return 200 "<!DOCTYPE html><h2>gangnam style!</h2>\n";...
52
votes
Why do I need Nginx and something like Gunicorn?
I liked this explanation in its simplicity:
Nginx will face the outside world. It will serve media files (images,
CSS, etc) directly from the file system. However, it can't talk
directly to ...
51
votes
Accepted
Nginx duplicate listen options for [::]:80 error
I'm creating an answer out of my earlier comment.
Please post the error message (nginx -t output) as it could contain some useful insight.
What nginx version are you running? Option ipv6only=on ...
49
votes
Dump nginx config from running process?
This will not help on this request, but might help other reaching here for the same reason. Newer nginx versions have the -T option to dump the nginx config read from all nginx config files, not from ...
49
votes
Properly setting up a "default" nginx server for https
I managed to configure a shared dedicated hosting on a single IP with nginx. Default HTTP and HTTPS serving a 404 for unknown domains incoming.
1 - Create a default zone
As nginx is loading vhosts ...
49
votes
What does the at-sign "@" mean in nginx location blocks?
In the example that you quote in your question:
location @default {
# ...
}
location /somewhere {
try_files $uri @default;
}
If the incoming request is received at http://your-domain/somewhere, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
nginx × 17207reverse-proxy × 1632
php-fpm × 1336
ssl × 1227
php × 1037
ubuntu × 1030
rewrite × 930
linux × 847
apache-2.2 × 724
redirect × 631
proxy × 624
docker × 581
wordpress × 565
web-server × 555
https × 535
configuration × 482
cache × 452
http × 408
load-balancing × 386
django × 371
centos × 357
fastcgi × 351
proxypass × 327
ssl-certificate × 312
node.js × 312