nginx only serving welcome index page - html

I'm running nginx off of EC2 server
to try to troubleshoot this I created a separate directory usr/loca/nginx/html/test and put a copy of the index.html file there. I deleted the original index.html file from usr/loca/nginx/html
here is my relevant code...
nginx.conf.default
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
include usr/local/nginx/conf/*.conf
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html/test;
index index.html index.htm;
}
}
i try to access the site by http://'public ip address'/index.html and all i get is the default nginx startup page; even though i deleted this file, and even though i changed the text in the original index.html file to something else
i tried reloading nginx and clearing cache etc.....

I think your root directive is not pointing to the correct location. Your root directive is relative i.e. relative to the current folder. This is a very bad thing to do. Always do root relative directive. I will do something like
/home/user/www/localhost
You can choose a directory of you liking but make it root relative. Note the leading slash. If welcome page is working then NGINX is working correctly and the fault usually lies in wrong root directive. You can also make the following improvements.
First of all get the root out of sever block. Putting root in the server block is bad.
http://nginx.org/en/docs/beginners_guide.html#proxy
Why is your Nginx configuration file called nginx.conf.default? It should just be called nginx.conf (this may also be leading to the problem). See if you have a file called nginx.conf and make changes to that.
Why are you declaring the server inside nginx.conf? It is better to declare it inside a folder like
sites-available/localhost
sites-available/somesite
...
Then create a symlink to sites-enabled. This is not required but it is a good practice.

Related

nginx does not use modified index file

I installed nginx on my raspberry pi, and configured it.
However, it does not work as what I want.
The IP of raspberry pi is 192.168.0.182, so I made index.html fil and typed in my browser. But, it show nginx's default message, not my index.html.
If I use 192.168.0.182/index.html, it shows my index.html.
What I want it not to use "/index.html" after IP address for index.html. How shoud I configure nginx?
This is my nginx configuration in /etc/nginx/site-available.
server{
listen 80;
root /home/xaliver/Web/www;
index index.html index.htm;
}
and I linked it by
sudo ln -s /etc/nginx/site-available/mysite /etc/nginx/site-enalbled/
Also, I putted index.html in /home/xaliver/Web/www/. The index.html is
"Hello World"
Please, let me know what I missed.
Thank you.

How to serve any static directory containing web pages in django?

I'm working on an application where we want the following to happen:
The administrators upload zip archives containing web content (whole static websites) through admin interface
The archive is unzipped in the background to a random directory
The static content is served at a url that looks like http://<host>/site/<user-friendly-url>/, with the index.html at the root, all the paths to css and js files, etc.
I know how to configure the route, but I was wondering what to put in the view. I have tried with STATIC_{ROOT,URL} and MEDIA_{ROOT,URL} but I feel it's not the right way.
In summary : is there a way to put something like return serve_this_static_directory() in the view? or is there any workaround there?
Thanks for your answers
edit:
Trying to clarify my question.
The url (http://<host>/site/<user-friendly-url>/) doesn't match the directory name (which could be anything, like XYZ_html/).
Administrators must be able to upload new archives, which should be extracted and served automatically.
For those two reasons, I don't have any idea how to serve this content using the webserver, because how is it possible to configure the routes then?
First you must realize that django won't serve your static or media files by default, you should use your HTTP server (nginx, apache or other) for that.
Next thing to do is to configure your HTTP server to serve "/path/to/your/project/public" and any files inside on root URL of your domain, and instead of serving 404 error if file is not found, it should redirect to django (so if there is some file in path /site/something/ your HTTP server should serve that file, if not, it shoudl serve anything that django will output on that path. Sample configuration for nginx might look like this:
server {
listen 80;
server_name oskar.local;
root /path/to/your/project/public;
location #default {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
include /etc/nginx/uwsgi_params;
uwsgi_pass app_server; # or some proxy_pass if you're not using uwsgi
break;
}
location / {
try_files $uri #default;
}
}
And last step is to configure your django app's MEDIA_* settings:
MEDIA_ROOT = "/path/to/your/project/public"
MEDIA_URL = "/"
But be careful! With that approach there is potential vulnerability: any user can put files into path that is normally handled by django. Better approach will be to put all of "sub-sites" inside some sub-directory or into separate domain.

Nginx: how to let rewrite rules ignore files or folders

I use Nginx to serve a SPA (Single Page Application), in order to support HTML5 History API I have to rewrite all deeper routes back to the /index.html, so I follow this article and it works! This is what I put in nginx.conf now:
server {
listen 80 default;
server_name my.domain.com;
root /path/to/app/root;
rewrite ^(.+)$ /index.html last;
}
However there's one problem, I have an /assets directory under the root contains all the css, js, images, fonts stuffs, I don't want to rewrite these urls, I just want to ignore these assets, how am I suppose to do?
Put rewrite into one location and use other locations for assests/dynamic urls/etc.
server {
listen 80 default;
server_name my.domain.com;
root /path/to/app/root;
location / {
rewrite ^ /index.html break;
}
location /assets/ {
# Do nothing. nginx will serve files as usual.
}
}

Nginx css and js 404

I have the below in my nginx file for a domain:
location / {
root /home/dpk/apps/abc/site;
index index.html;
}
When I access the domain, only the text is visible, all static files like favicon.ico, css and js files are giving a 404 error. As a result the layout is completely broken.
css is located in /home/dpk/apps/abc/site/assets/home.css and similarly js is stored in /home/dpk/apps/abc/site/assets/home.js.
The root directory is recursively owned by www-data and all files are 755. This is a pure html website and no other language like php is being used.
I guess I am missing something in the configuration. Any suggestions?
I got it working by using just root /home/dpk/apps/abc/site; instead of the below.
location / {
root /home/dpk/apps/abc/site;
index index.html;
}

AWS page just showing Apache Start page and not html file

I'm running an apache server on an Amazon EC2 basic linux instance, and I'm trying to get it to just display a simple test html file that I created. The file is in /home/ec2-user/public_html (just for test purposes). I've changed the DocumentRoot and Directory to point to this directory, but the public dns address is still just showing the default Apache start page. What else do I need to do/change to get this to actually display online?
Edit: I've also uncommented the VirtualHost *:80 line, changed the DocumentRoot and ServerName within the VirtualHost tags.
It turns out I had forgotten to change some permissions on the test.html file itself and that was causing a holdup.
check running instance's security group HTTP rule. ADD rule if not added:
Select HTTP from the Type list, and leave the source as Anywhere (0.0.0.0/0).