Nginx css and js 404 - html

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;
}

Related

Have index.html file but still getting a directory listing

I have an index.html file in my Apache DocumentRoot directory but when I go to my URL, I am still getting a directory listing of my DocumentRoot directory instead of the index.html file being displayed. The apache access_log shows 200's when I reload the page. Any suggestions?
Use
DirectoryIndex index.html
It tells apache what document to show for a directory request.
update
You should specify just the filename that apache will look for in the folder requested.
Not saying this will fix it for you, but for me when first getting started with Apache2 it was file permissions that would get forgotten when moving or writing new file under the web root directory
ls -hal /var/www/host_one/index.html
If above doesn't have read (r) permissions for the same user:group or if the ownership doesn't include the user/group of the web server, then try the following for allowing group reads
# Modify ownership, change 'www_host' to Apache2 group
chown ${USER}:www_host /var/www/host_one/index.html
# give read+write (6) to user and read (4) to group owners
chmod 640 /var/www/host_one/index.html
Try refreshing the website and see if permissions where the issue. Note most web documents only require read permissions and ownership to be correct for browsers to be allowed to pick them up for rendering, on rare occasions you may need executable (1 or x) permissions for server scripts (be cautious of ownership in such cases) and last write permissions (2 or w) should likely never be seen without good reasons on files within your web root.
Second thing to try, use the index.html within your browsers URL bar
# by IP
http://192.168.0.100/index.html
# by domain
http://site-name.local/index.html
If the above loaded your document then, like #Pekka 웃 stated already, you've likely got a server option that's missing or enabling directory listings instead of looking for a index page within that directory. If this is the problem then there's two ways of fixing it that I've tried in the past. One, htaccess configuration to disable directory listing within that sub-directory, two, server vhost configuration to prevent whole site from directory listings. Personally I prefer to use option two and then on directories that should be allowed to be listed place an htaccess config for permissions instead of denials.

Index.html file is named as parent directory?

I have an contact.html file on the server in public_html.If I Move it into directory named: Contact, & rename it to index.html,does browser's Address bar shows it like: example.com/Contact/ ? I mean the name of file doesn't show up.
ANY help is appreciated.
Yes, example.com/Contact/ would work, but only if the server is configured with a default document index.html.
This is standard behaviour for apache web servers.
In your apache config there is a directive called
DirectoryIndex index.html ...
This tells the webserver to serve index.html in the case that a directory call was requested ... ie your example.com/Contact/ [Is a directory].
To change that behaviour you would need to look into change your server config, or adding an .htaccess file that would rewrite the URL to index.html

Default file other than index.html

Is there a way to have a file other thing index.html or index.md served as a folder's default file? Specifically, I'm looking to keep my .json file extention, but have it reference-able as /api-docs/myapi/ instead of /api-docs/myapi/myapi.json.
This configuration is mostly in your web server. You can set the files for the server to look for to index.json (as well as index.html and index.htm which are common on most servers). For example, this can be configured on nginx by adding this to your server block:
index index.json index.html index.htm;
If nginx gets a request for /some/folder, it will try to serve /some/folder/index.json, /some/folder/index.html, /some/folder/index.htm then your 404 page with this configuration.
You can use permalink in your yaml front matter :
Permalink: api-doc/myapi/myapi.json
Edit: As #SAMdroid pointed it, I misunderstood the question, and as he says in is answer, it's a server configuration matter. But, it's sadly not possible to change default served page on Github Pages.
Your json can only be reached at api-doc/myapi/myapi.json

nginx only serving welcome index page

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.

Html, external CSS link fails on Linux

I know similar questions have been asked but cannot see why our external css link doesn't work on Linux. The folder structure on both Windows and Linux is:
/
/static
/css
style.css
/img
/js
/html
index.html
The index.html links to style.css with:
<link rel="stylesheet" type="text/css" href="../static/css/style.css" />
It works on Windows but fails on Linux with a 404. This would imply that the /static folder and sub-folders don't have the correct permission but they actually have identical permissions as the /html folder. If all the /static content is placed in the /html folder then it works.
Has anyone come across a similar situation or know what the problem is?
Are you using mod_rewrite ? It has to be a server config issue. Make sure it is configured right
To be sure the path is ok, open index.html on the browser and check the path of css file from the page source there.
The problem can probably be permission on the css file.
The user apache ir running on must be able to read the file, otherwhise it will fail to load it
you can try running:
chmod a+r style.css
to add read permission to everyone on that file, or:
chown [user]:[group] style.css
to change the owner of the file to the user and group apache is using.
You can also check which user apache is running on in this question Finding out what user Apache is running as?
By default it usually is apache user and apache group.