I can't get any changes in the /etc/nginx/nginx.conf http block to be used. I'm starting with the simplest thing - I want to modify the name of access.log to something else (ie a.log). It is a vanilla nginx install (no custom config files yet). Here's what I know:
changing a value in the head of nginx.conf does affect the configuration (changing worker_processes 4 to worker_processes 2 does change the # of workers)
Making a syntax error in nginx.conf's http block does cause nginx to throw an error on restart
Changing access_log to access_log /var/log/nginx/a.log does not modify the location of the log, and nginx in fact continues logging to /var/log/nginx/access.log
Here is a snippet of my nginx.conf file:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/a.log;
#....
}
Is it something as simple as I'm modifying an http block that gets overwritten by some other config file? Thanks for the help.
Isn't your access_log also defined in a server block ? Have a look at the default config in nginx/sites-enabled/.
In this case the value in http block is overwritten by the one in the lower block.
Related
I'm trying to dabble in Nginx and making my first server thingie, but it's not working. Here is my config file
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
location / {
root ~/42cursus/ft_server/tests/www;
}
location /images/ {
root ~/42cursus/ft_server/tests;
}
}
include servers/*;
}
I've been following this beginner's guide : https://nginx.org/en/docs/beginners_guide.html. The only thing I did different was delete the commented lines in the default config file in order for it to be clearer to me.
Whenever I send nginx -s reload, I get a "signal process started" added to my error.log, and trying to access the site via localhost just shows This.
Could someone help me, keeping in mind that I'm on a school computer and can't use SUDO ? Thank you in advance.
Added "listen 80;" to my server block, and now I get a 404 instead of nothing, at least that's progress !
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!
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
I'm using nginx 1.4.1. After copying unicorn's example of nginx.conf, I found out the settings must be moved to different directives. I still couldn't manage to place the following settings in the nginx.conf file: worker_processes, user, pid and events block. When I place them as it is now, the log shows directive is not allowed here. What should I fix?
worker_processes 1;
user deployer sudo; # for systems with a "nogroup"
pid /run/nginx.pid;
events {
worker_connections 1024; # increase if you have lots of clients
accept_mutex off; # "on" if nginx worker_processes > 1
}
upstream abc {
...
}
server {
...
}
Update 1
I know about this post, but it's weird that whatever I am doing is not working. I couldn't find any docs in nginx.
The original example cannot be used directly, because the main configuration is at /etc/nginx/nginx.conf. /etc/nginx/nginx.conf has http directives, which includes the sites-enabled/* directives. The only changes to be made on /etc/nginx/nginx.conf are:
work_processes 4;
worker_connections 1024;
Also, remove text/html from it because it's already gzipped by default.
The end result of your nginx.conf in your app should have no http directives, just upstream and 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.