I use nginx with Incapsula CDN and need to cleanly block all another requests in nginx's server context (for certain domain names, but not for all nginx's connections). Best practice in my opinion is return no answer, if client IP not in Incapsula's ranges, like a webserver who has no configuration for this domain. How can I do it ?
(In some cases, you might want to return a response that is more complex or nuanced than you can achieve in a text string. With the error_page directive, you can return a complete custom HTML page for each HTTP code, as well as change the response code or perform a redirect.)
So the return directive is simple to use, and suitable when the redirect meets two conditions: the rewritten URL is appropriate for every request that matches the server or location block, and you can build the rewritten URL with standard NGINX variables.
Like the return directive, you enclose the rewrite directive in a server or location context that defines the URLs to be rewritten. Otherwise, the two directives are rather more different than similar, and the rewrite directive can be more complicated to use correctly. Its syntax is simple enough:
This is less efficient than the equivalent return directive, because it requires NGINX to process a regular expression, albeit a simple one (the caret [ ^ ], which matches the complete original URL). The corresponding return directive is also easier for a human reader to interpret: return 301 more clearly indicates that NGINX returns code 301 than the rewrite ... permanent notation does.
You might want to provide clients with a more accurate indication of the reason for the failure, by returning response code 403 (Forbidden) and an explanation such as "Server handles only Ruby requests" as the text string. As an alternative, the deny all directive returns 403 without an explanation:
I've noticed though that when I'm logged in the application and I change https to http and trigger the request the redirect works. When I'm logged out, the redirect fails and renders the https url without the www.
The ngx_http_auth_request_module module (1.5.4+) implements client authorization based on the result of a subrequest. If the subrequest returns a 2xx response code, the access is allowed. If it returns 401 or 403, the access is denied with the corresponding error code. Any other response code returned by the subrequest is considered an error.
To return the index file, NGINX checks for its existence and then makes an internal redirect to the URI obtained by appending the name of the index file to the base URI. The internal redirect results in a new search of a location and can end up in another location as in the following example:
The last parameter can also be a status code (directly preceded by the equals sign) or the name of a location. In the following example, a 404 error is returned if none of the parameters to the try_files directive resolve to an existing file or directory.
As I was testing if all urls work, I noticed, that there are urls like example.com/node&a=b (without ?), which return 200 on Drupal 6 site and 404 on Drupal 7 one. (Normal urls like example.com/node?a=b are served with 200)
I'm using the Drupal 7 rule and it tells Nginx to just execute the /index.php without any argument handling. Next, Drupal initializes and runs the drupal_environment_initialize() function, which calls therequest_path() function. Here Drupal tries to parse the $_SERVER ['REQUEST_URI'] variable. And of course, here is no special handling for malformed urls, I see in my logs.
I'm running into a few issues trying to set up 301/302 redirects with Craft and nginx. The legacy site has /contact.php paths which I would like to direct to /info/ but when I visit mysite.com/contact.php it gives me the No input file specified. error.
Hey guys this is my first time working with Grav so bear with me. I finally got the Grav homepage up and running on a local Mamp server but any new page I add to the site just returns an nginx 404 error page.
I Found the nginx config file within the MAMP directory. It had some of the info on my project so I copied over to my projects config file. These are the exact server info settings I have at the moment.
An Nginx server block is denoted by a server section within the configuration files. Usually, there is one for the Nginx default website and then several others either within that same nginx.conf file or within a directory, perhaps called conf.d or sites-available/sites-enabled. The server blocks within conf.d/sites-available are then included in the main nginx.conf file.
I would start by modifying your root location block and adding it the other security-related location blocks (those which return a 403). If the site loads, then we know that was this simple configuration issue of missing the appropriate Nginx configurations for the software.
Do i have put "try_files $uri =/index.php?$query_string;;" in every try_files? Im so sorry im very new in nginx and drupal, so could you point out where do you want me put" @rewrite" because there are so many location places. I have tried it to put it. But im it wasnt working. Thanks
I am trying to install bitwarden on a Ubuntu 20 server.
I already have nginx and certbot installed handling the http to https.
I am serving several domains with this set up and it works fine. All http traffic is refused and the requesting browser/computer then uses https (if it can).
Doing it this way I can have several separate domains along with individual certificates (handled by certbot)
I can manually install bitwarden (without using the bitwarden.sh)
This works fine BUT the method of providing an admin token has changed. I am now unable to provide a token as the method is now to set an environmental variable email address and a token is sent each time admin access is required
If I use bitwarden.sh to install I can then add the variable as normal but it is installed with another instance of nginx and (yet another set of certificates) I do not want to have to copy certificates from the default letsencrypt location every time they are renewed or docker is rebuilt etc.
Is there anyway to stop the generation of the nginx in the docker?
I believe I could possibly fiddle with the ports in the bitwarden nginx and change the config to effectively bypass the instance of nginx, but that still leaves the problems of the certificates.
At the moment nginx is working as a reverse proxy as it should.
Is bitwarden.sh able to write global environmental variables in the command line?
I could have nginx bypass the bitwarden domain and reverse proxy it as is to the docker nginx server but again the certificates become prolematic. I would rather not have any http bypass the nginx if at all possible
Any suggestions would be much appreciated.
Well after much gnashing of teeth, bouts of unrestrained swearing I worked it out.
Simple really.
1 setup docker
2 setup nginx
(leave the default file alone!)
3 setup test files as follows /var/html/your.first.domain/public_html/index.html
4 setup test files as follows /var/html/your.second.domain/public_html/index.html
5 setup test files as follows /var/html/your.third.domain/public_html/index.html
(each index file should contain some HTML code including the domain name so you can identify it)
You should be able to get to each domain with http (http:// example your.first.domain
6 In the /etc/nginx/sites-available create empty files with the SAME name as your domains (in this case 3 files named your.first.domain your.second.domain your.third.domain)
These files along with the file called default are the configuration files for all the domains that nginx will service.
create a symbolic link from all these files to /etc/nginx/sites-enabled
(example sudo ln -s /etc/nginx/sites-available/your.first.domain /etc/nginx/sites-enabled/your.first.domain)
7 Install certbot and run it. The certbot webpage has superb step by step instructions.
it will interactively create the certificates, set up a cron job to update them as required, and also modify the files you created.
8 sudo nginx -t will make sure everything went right
9 sudo service nginx restart
10 Now when you try to go to a http site nginx will negotiate and change to https (example your.first.domain will now change to )
You can just not create the 3 files and certbot will just add the configuration to the default file. (I found it easier to make individual files so that changes to one file did not effect the other domains).
What I found was that without the nginx, the bitwarden was served on *.example.com host rather than the vault.example.com. That will interfere with any other pages. For example i could get to the vault on vault.example.com as well as www.example.com
The 444 status code is not a standard HTTP status code and is specific to the Nginx web server. It indicates that the connection to the server was closed without any response from the server. Since it is specific to Nginx, troubleshooting this error requires checking the Nginx configuration and logs.
The following snippet has been thoroughly tested on NGINX, and actually returns a status code of 418 along with the page, just as Mr. L. Masinter intended. No guarantees of course, the above code is provided free at charge with no warranties, use at your own risk.
After the minor version upgrade from 14.9.3 to 14.10.5, the root domain of my GitLab instance returns a blank HTTP 200 response. All other paths just return 404. I changed no configuration files before this upgrade.
All the permissions seem fine for the gitlab-www user to reach the socket. The nginx workers are running as that user. I even temporarily set a shell for gitlab-www in /etc/passwd and curled the socket successfully after doing su gitlab-www.
I did a quick comparison of the two instances by md5sums of key config files. Before and after the 14.10.5 upgrade, the config files in /var/opt/gitlab/nginx/conf are identical. All the permissions on the socket file and its parent directories are identical. gitlab.rb is identical. /var/opt/gitlab/gitlab-rails/etc/gitlab.yml is identical. Both instances have ample free disk space.
f5d0e4f075