Is it possible to change server_tokens directive not in nginx.conf? - nginx

I need to uncomment the following line in nginx.conf
#server_tokens off;
But I don't want do it in nginx.conf directly so is it possible to make this change in another place like in some config files placed at /etc/nginx/conf.d/ directory?

This can be changed in either http, server or location block.
syntax: server_tokens on | off;
default: server_tokens on;
context: http, server, location
Enables or disables emitting nginx version in error messages and in the “Server” response header field.
Source: http://nginx.org/en/docs/http/ngx_http_core_module.html#server_tokens

Related

Overwrite nginx.conf option keepalive_timeout in http{} keeping default nginx.conf file

I have an nginx HTTP server in which I want to have keepalive_timeout 10s 10s;.
I would just add it in a file in /etc/nginx/conf.d/, however the default nginx.conf already contains keepalive_timeout 65s;, so if I simply do that, nginx complains because of defining that value twice.
So my workaround was to have a custom nginx.conf file where I removed that line, and then I could have my other file in conf.d. But it would be simpler if I could solve it without having to change the default file, so I would only have to add things into conf.d.
Is it possible anyhow?
According to the docs you can define the keepalive_timeout in any of http, server, location directives, so you can add keepalive_timeout 10s 10s; to your specific server or location directive and it will override the default.

nginx webdav could not open collection

I have built nginx on a freebsd system with the following configuration parameters:
./configure ... –with-http_dav_module
Now this is my configuration file:
user www www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
# reserve 1MB under the name 'proxied' to track uploads
upload_progress proxied 1m;
sendfile on;
#tcp_nopush on;
client_max_body_size 500m;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#upload_store /var/tmp/firmware;
client_body_temp_path /var/tmp/firmware;
server {
server_name localhost;
listen 8080;
auth_basic "Restricted";
auth_basic_user_file /root/.htpasswdfile;
create_full_put_path on;
client_max_body_size 50m;
dav_access user:rw group:r all:r;
dav_methods PUT DELETE MKCOL COPY MOVE;
autoindex on;
root /root;
location / {
}
}
}
Now, the next things I do are check the syntax of the confiuration file by issuing a nginx -t and then do a graceful reload as follows: nginx -s reload.
Now, when I point my web-browser to the nginx-ip-address:8080 i get the list of my files and folders and so on and so forth (I think that is due to the autoindex on feature).
But the problem is that when I try to test the webdav using cadaver as follows:
cadaver http://nginx-ip-address:8080/
It asks me to enter authorization credentials and then after I enter that it gives me the following error:
Could not open Collection: 405 Not Allowed
And the following is the nginx-error-log line which occurs at the same time:
*125 no user/password was provided for basic authentication, client: 172.16.255.1, server: localhost, request: "OPTIONS / HTTP/1.1", host: "172.16.255.129:8080"
The username and pass work just fine wheni try to access it from the web-browser, then what is happening here?
It turns out that the webdav module in-built in nginx is broken and to enable full webdav, we need to add the following external 3rd party module: nginx-dav-ext-module.
Link to its github: https://github.com/arut/nginx-dav-ext-module.git
The configure parameter would now be:
./configure --with-http_dav_module --add-module=/path/to/the/above/module
The built in one just provides the PUT DELETE MKCOL COPY MOVE dav methods.
The nginx-dav-ext-module adds the following additional dav methods: PROPFIND OPTIONS
You will also need to edit the configuration file to add the following line:
dav_ext_methods PROPFIND OPTIONS;
After doing so check if the syntax of the conf file is intact by issuing: nginx -t
and then soft reload (gracefully) nginx: nginx -s reload
And Voila! you should now be able to use cadaver or any other dav client program to get into the directories.
I cannot believe that I solved this, it drove me nuts for a while!

Route a url to a directory with nginx

Let's say this is the ip of a server running nginx:
1.2.3.4
Let's also say I've purchased this url:
www.abcd.com
I've edited the DNS records for www.abcd.com like so:
(Using Godaddy as a registrar)
A (host)
Host | Points To | TTL
# | 1.2.3.4 | Live!
Entering 1.2.3.4 into my browser's url bar will take me to my server's nginx welcome page. Because I pointed my url at the same address www.abcd.com also takes me to the same page, though it resolves to 1.2.3.4.
Here is my nginx config file:
sudo nano /opt/nginx/conf/nginx.conf #=>
http {
include /usr/local/nginx/conf/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
server_names_hash_bucket_size 128;
client_max_body_size 4M;
client_body_buffer_size 128k;
include /usr/local/nginx/conf/conf.d/*.conf;
include /usr/local/nginx/conf/sites-enabled/*;
upstream appname {
server unix:///data/apps/appname/shared/tmp/puma/appname-puma.sock;
}
server {
listen 80;
server_name www.abcd.com;
root /public/rails/test;
# keepalive_timeout 5;
}
}
On my server, I have the following structure:
~/public/rails/test/index.html
Here's what index.html contains:
sudo nano /opt/nginx/conf/nginx.conf #=>
<h1> It works! Routing from <i>www.abcd.com</i> has been successful! </h1>
What I expect to happen:
Visiting www.abcd.com would be forwarded to 1.2.3.4 by the nameserver. When the request arrives at 1.2.3.4, nginx would see that it's come from www.abcd and serve this file to the user:
~/public/rails/test/index.html
In short:
www.abcd.com => It works! Routing from www.abcd.com has been successful!
What actually happens:
Visiting www.abcd.com is forwarded to 1.2.3.4 by the nameserver. However, it's although my config file isn't working. It just displays nginx' "welcome" message to the user, as if I haven't touched my config file.
I've tried
sudo service nginx stop
sudo service nginx start
and
sudo service nginx restart
and after editing the config, but different nothing happens.
What am I doing wrong? Where can I find logs to see exactly what's happening? What does nginx' welcome screen signify? That my paths are wrong? What? Flying blind here.
Your server blocks root directive is set to /public/rails/test (absolute path), while you say you expect it to serve ~/public/rails/test/index.html to the user. The character ~ indicates the current users home directory, and is a relative path.
Therefore: Try setting the absolute path (for example /home/myuser/public/rails/test) in the server block.
Add server_name with and without www
Add this line index index.html;
add ~ sign before /public/rails/test. Like: root ~/public/rails/test;
Try with this:
server {
listen 80;
server_name abcd.com www.abcd.com;
index index.html; # add this line
root ~/public/rails/test; # add "~" sign '/public/rails/test'
server_name www.abcd.com;
}

ember.js application does not update hashtag part of URI with NGINX server

I have an ember.js application I developped on my local machine. I use a restify/node.js server to make it available locally.
When I navigate in my application, the address bar changes like this:
Example 1
1. http://dev.server:3000/application/index.html#about
2. http://dev.server:3000/application/index.html#/items
3. http://dev.server:3000/application/index.html#/items/1
4. http://dev.server:3000/application/index.html#/items/2
I try now to deploy it on a remote test server which runs nginx.
Although everything works well locally, I can navigate into my web application but the part of the URI that is after the hashtag is not updated.
In any browser: http://test.server/application/index.html is always displayed in my address bar. For the same sequence of clicks as in Exemple 1, I always have:
1. http://web.redirection/application/index.html
2. http://web.redirection/application/index.html
3. http://web.redirection/application/index.html
4. http://web.redirection/application/index.html
Moreover, if I directly enter a complete URI http://web.redirection/application/index.html#/items/1 the browser will only display the content that is at http://test.server/application/index.html (which is definitely not the expected behaviour).
I suppose this come from my NGINX configuration since the application works perfectly on a local restify server.
NGINX configuration for this server is:
test.server.conf (which is symlinked into /etc/nginx/sites-enabled/test.server.conf)
server {
server_name test.server web.redirection;
root /usr/share/nginx/test;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.csv$ {
alias /usr/share/nginx/test/$uri;
}
}
nginx.conf
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log debug;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
EDIT:
Just to be sure that there were no missing files on my test server: I ran a restify/node server (like on my dev machine) and everything works fine when I connect to this server (!). Both nginx and restify servers points to the same files.
EDIT 2
I discovered that my problem happens when I use a web redirection.
If I use an address like http://test.server/application/index.html everything works fine
If I use http://web.redirection/application/index.html it does not work.
So this is my nginx conf that is not correctly redirecting web.redirection URI to test.server or something like that.
Does someone has an idea ? What do I miss ? What should I change to make this work ?
EDIT 3 and solution
The web redirection I used was an A type DNS record. This does not work. Using a CNAME type DNS record solves the issue.
No, this has nothing to do with nginx, any thing past the # is never sent to the server, a javascript code should handle this, I would suggest to use firebug or any inspector to make sure that all your js files are being loaded, and nothing fails with a 404 error, also check for console errors on the inspector console.
The problem came from the DNS redirection from web.redirection to test.server.
It was an A-type record: this does not work.
Using a CNAME-type record that points directly to test.server works.

NGINX [emerg] unknown directive "upload_pass" error in a config file

I have installed Nginx 1.2.0 with Passenger on my Mac Mini running Lion Server. I used the instructions from the link below.
https://github.com/coverall/nginx
I will state upfront that I am new to Nginx & Passenger. I am working on a Ruby on Rails project that I would like to host on the server. When I try to start Nginx I get the following error:
[emerg] unknown directive "upload_pass" in /usr/local/etc/nginx/virtualhosts/adam.localhost.coverallcrew.com.conf:20
Here are lines 19 & 20 from the file in question. This is a file that I assume was included in the Nginx installation. The only config file I have done anything with is nginx.conf where I added the lines to hopefully host my Rails application.
# pass request body to here
upload_pass #fast_upload_endpoint;
This is my second attempt at doing extensive web searches on how to correct this error. I had hoped to find if I needed to add something to nginx.conf or something to get upload_pass defined somewhere but only found solutions where the directive was indeed missing.
I took a look at nginx.conf. There are a lot of statements commented out. Here are the ones that are not:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
gzip on;
server_name_in_redirect off;
port_in_redirect off;
client_max_body_size 8m;
client_body_buffer_size 128k;
include upstreams/*.conf;
include virtualhosts/*.conf;
include third-party/*.conf;
server {
listen 8080;
server_name www.lightbesandbox2.com;
root /Sites/iktusnetlive_ror/public;
passenger_enabled on;
}
}
Another question: Do I need these virtual hosts that were including in the Nginx install?
Any help would be appreciated.
It appears your Nginx is not compiled with the upload_pass module so it does not understand that directive. I am not certain how to do this with homebrew, but you can compile it in:
./configure --add-module=/path/to/upload_pass/source

Resources