Nginx config file not reloading - nginx

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 !

Related

NGINX dynamic location | alias

I have a driver i need to distribute to my users, using an angular website, till here is ok, but the problem is here. The download is handled by nginx using "location" like this:
location /download/windows-driver.exe {
alias /opt/dist/windows/driver-windows-64-1.0.0.exe;
types { application/octet-stream; }
default_type application/octet-stream;
add_header Content-disposition "attachment";
}
location /download/linux-driver.run {
alias /opt/dist/linux/driver-linux-amd64-1.0.0.run;
types { application/octet-stream; }
default_type application/octet-stream;
add_header Content-disposition "attachment";
}
Then my question is, every time i upgrade my driver version, should i go manually to nginx and change it? isn't there any way to make it dynamic?
I've been searching a way to make nginx use some unix commands to read the driver folder and user the latest version, but i have not been successful.
Any solution or clarification will be appreciated, Thank you.

Changing Nginx Log File Location

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.

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.

Resources