Skip to main content
202 votes
Accepted

Does nginx support comment blocks in configuration?

Nginx configuration files do not support comment blocks; they only accept # at the beginning of a line for a comment. You can also have a valid statement followed by a # and then a comment on the same ...
dr_'s user avatar
  • 30.1k
37 votes
Accepted

Nginx reverse proxy redirection

Do not set proxy_redirect to off, that is not doing what you think it is doing. proxy_redirect performs something similar to URL rewriting, for example: location /sales/ { proxy_pass http://...
grochmal's user avatar
  • 8,707
33 votes

Do I Need to Restart Nginx if I Renew My Security Certificate(s)?

On receiving SIGHUP nginx will reload updated configuration, verify it while opening log files and reading SSL certificates, then gracefully shut down worker processes relying on previous ...
sanmai's user avatar
  • 1,436
23 votes
Accepted

How to configure NGINX as a reverse proxy for different port numbers?

The ssh protocol is not based on HTTP, and, as such, cannot be proxied through the regular proxy_pass of ngx_http_proxy_module However, recently, starting with nginx 1.9.0 (released as stable with 1....
cnst's user avatar
  • 3,283
22 votes

Installing Let's Encrypt on Amazon Linux 2023

I managed to get certbot installed in Amazon Linux 2023 in /opt/certbot/bin/certbot using the following commands: sudo dnf install -y augeas-libs sudo python3 -m venv /opt/certbot/ sudo /opt/certbot/...
Jens Møller's user avatar
21 votes
Accepted

Shell script: How can I write multiline content to file if the file doesn't exist?

summary : use >> to append, use [ -f file ] to test. try if [ ! -f myfile ] then cat <<EOF > myfile server { listen 80 default_server; listen [::]:80 default_server; ...
Archemar's user avatar
  • 31.7k
21 votes
Accepted

Why is the Nginx webserver called a "reverse proxy"?

A typical "forward" proxy (commonly just called "proxy") is used to allow internal clients to reach out to external sites. For example, a corporation may have desktop users who want to reach the ...
Stephen Harris's user avatar
16 votes

Problems to install nginx-full on debian 8

in my case I executed sudo apt-get remove nginx* --purge after that I installed nginx-common sudo apt-get install nginx-common then I installed nginx sudo apt-get install nginx after this I typed ...
shahab kamali's user avatar
16 votes
Accepted

Nginx location ~ /\.ht

location ~ /\.ht { deny all; } This directive tells the webserver to deny all incoming requests for any files starting with .ht in the root directory (/). The tilde ~ tells nginx to use regular ...
Tanner Babcock's user avatar
15 votes

How to configure NGINX as a reverse proxy for different port numbers?

Since Nginx Version 1.9.0,NGINX support ngx_stream_core_module module, it should be enabled with the --with-stream. When the stream module is enabled, it is possible to ssh protocol via a TCP proxy. ...
Hendi Fauzi's user avatar
15 votes
Accepted

Block access to a file or location on Nginx

The config below should cause nginx to respond to the "abuse" URLs with a 404 status and a basic nginx, 404 page; all other URLs ending in .php should be proxy passed to the application/php engine as ...
the_velour_fog's user avatar
13 votes
Accepted

Nginx Add Secure Flag to Cookies from proxied server

I know two ways to sorta do this, neither of them great. The first is to just abuse proxy_cookie_path like this: proxy_cookie_path / "/; secure"; The second is to use the more_set_headers directive ...
Larry's user avatar
  • 146
12 votes

Configuring ulimit of `max open files` for daemonized nginx master process

It seems the problem, so to speak, was my wrong assumption that a systemd service respects the ulimit configured in /etc/security/limits.conf. As it turns out a daemon configured via systemd does ...
Gregory Igelmund's user avatar
11 votes
Accepted

The correct way of implementing SSL on localhost

Warning: Before you dive into the minefield of running your own Certification Authority, you may need to study the security implications! But if you must, read on for a quick and dirty CA that will ...
garethTheRed's user avatar
  • 34.2k
11 votes
Accepted

How to resolve (40: Too many levels of symbolic links) on Ubuntu 10.04 AWS EC2 Instance

You have linked django.conf back to itself. There's no data in the file, just a reference to itself. This command, ln -s django.conf /etc/nginx/sites-enabled/ # Wrong creates a symbolic link in /...
Chris Davies's user avatar
10 votes

SELinux is preventing NGINX from writing via PHP-FPM

setsebool -P httpd_can_network_connect on will permanently enable the flag which should solve your problem.
13dimitar's user avatar
  • 1,579
10 votes
Accepted

Can't uninstall or disable nginx

Raspbian uses systemd to manage services by default, not SysV. Hence sysv-rc-conf and chkconfig having an inconsistent behaviour. To disable nginx upon boot do: sudo systemctl disable nginx.service ...
Rui F Ribeiro's user avatar
10 votes
Accepted

NGINX not passing all request headers to Tomcat

Headers containing underscores are considered invalid by nginx, which is why it will not pass them by default. The behaviour can be overridden by the underscores_in_headers directive. For example: ...
Richard Smith's user avatar
10 votes
Accepted

A utility to email myself if my site is down

Best bet is to use a service like uptime robot. Free tier will cover less than 50 sites, pro plan is quite cheap. It'll do a simple ping check or even HTTP status code check The upshot of this is ...
Outurnate's user avatar
  • 1,219
10 votes

Why is the Nginx webserver called a "reverse proxy"?

Why is the Nginx webserver called a "reverse proxy"? "Reverse proxy" refers to a specific function that a specific Nginx instance can take on. Other Nginx instances can be ordinary web servers, or ...
Adrian's user avatar
  • 2,606
9 votes

Installing Let's Encrypt on Amazon Linux 2023

Thank you to Jens for getting me on the right track. However, I found I needed additional steps to get it fully working. You may also need the module(s) for your specific web server software, and I ...
Rich Brome's user avatar
8 votes

nginx: Long filenames in directory listing

You can try fancyindex module with its fancyindex_name_length parameter to configure the filename length.
Jack Rowe's user avatar
8 votes
Accepted

Updating Nginx server to 1.10 on Debian 8.4

The basic error is this (emphasis mine): dpkg: error processing archive /var/cache/apt/archives/nginx_1.10.0-1~jessie_i386.deb (--unpack): trying to overwrite '/etc/default/nginx', which is also in ...
terdon's user avatar
  • 244k
8 votes
Accepted

Nginx on FreeBSD: fcgiwrap.sock permission denied

The RC script is located at /usr/local/etc/rc.d/fcgiwrap. Looking at the code, fcgiwrap_user sets the owner of the process running the daemon (default root). You need to set fcgiwrap_socket_owner="...
Richard Smith's user avatar
8 votes
Accepted

Is there a way to use a variable in nginx config?

The syntax is set $variable_name variable_value; Then you can reference $variable_name in subsequent lines of the Nginx config. See more here. It is a feature of the rewrite module and not a feature ...
rubynorails's user avatar
  • 2,314
7 votes

Nginx doesn't work, no permissions rights and can't find some dir

In my case, I created new directories: mkdir -p /var/lib/nginx mkdir -p /var/lib/nginx/body mkdir -p /var/lib/nginx/fastcgi That worked for me.
Kaushik Thirthappa's user avatar
7 votes
Accepted

Installing nginx on redhat - error missing libpcre.so.0

If you're running RHEL/CentOS 7, you'll probably want the 7 packages at http://nginx.org/packages/rhel/7/x86_64/RPMS/, not the ones for RHEL 6.
Ulrich Schwarz's user avatar
7 votes
Accepted

Nginx 403 error, when nginx.conf set to serve from /websites

The error log very clearly says: Your nginx would try to read /websites/index.html, but it can't This is why it gives 403 error, not because of its configuration. It is because of the 13: Permission ...
peterh's user avatar
  • 9,828
7 votes
Accepted

Is the www-data user pre-configured in Linux and Unix systems?

Since you’re using Ansible, you should specify that you want a www-data user to be present, using the user module with state=present and whatever other attributes are appropriate (e.g. system=yes). ...
Stephen Kitt's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible