Nginx throw 404 not found Error on html page
my index.html page is in /var/www/html directory
and nginx default configuration is given here:
server
{
listen 80 default_server;
server_name localhost;
root /var/www/html;
index index.html index.htm;
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
Related
I have the below configuration for nginx,
server {
listen 80;
root /vol/www/home;
index /index.html;
error_page 404 /404.html;
location = /404.html {
internal;
}
location / {
try_files $uri $uri/ =404;
}
location /about {
try_files /about.html =404;
}
}
this is working well, but when I select some paths in the home page say About Us page, the uri comes with the full filename including the ending .html. I was able to get ride of those by adding a separate location in the nginx configuration and changing all the href links to the location instead of filename. So that is one workaround to get ride that but to run locally without server it is not possible.
I have seen a rewrite config in nginx, but I was unsuccessful with that. So I am here to ask how do I setup the uri without a html part in it and without modifying the href path to a uri instead of filename.
My configuration is like so, but it is not working
server {
listen 80;
root /vol/www/home;
index /index.html;
error_page 404 /404.html;
location = /404.html {
internal;
}
location / {
rewrite ^\/(.*)(\.html)?$ /$1 last;
try_files $uri $uri/ /index.html =404;
}
}
A 500 error is thrown : rewrite or internal redirection cycle while processing "/"
replace this to
rewrite ^\/(.*)(\.html)?$ /$1 last;
try_files $uri $uri/ /index.html =404;
this
rewrite ^(/.*)\.html(\?.*)?$ $1$2 permanent;
rewrite ^/(.*)/$ /$1 permanent;
try_files $uri/index.html $uri.html $uri/ $uri =404;
i need help about my Nginx configuration file. I coded my html file. This is the config file:
server
{
listen 888;
server_name phpmyadmin;
index index.html index.htm index.php;
root /www/server/phpmyadmin;
location ~ /tmp/ {
return 403;
}
#error_page 404 /404-error.html;
location ~ /*-error.html {
try_files $1-error.html #error;
internal;
}
location #error {
root /var/www/wwwroot/umutisik.com/error_docs;
}
Also sorry for my bad English, not my main language.
I tried below nginx config:
server {
listen 80;
server_name mysite.com;
location / {
root /var/www
index index.html;
try_files $uri.html $uri #proxy;
access_log off;
}
...
}
But I couldn't access to my site with /. I can access to my site with /index or /index.html though.
How can I access to mysite with /?
I am trying to change the site which get's returned to the client when no certificate has been sent. My config is below:
server {
error_log /tmp/error.log;
listen 443;
ssl on;
server_name router.local;
ssl_certificate /tmp/server.crt;
ssl_certificate_key /tmp/server.key;
ssl_client_certificate /tmp/ca.crt;
ssl_trusted_certificate /tmp/ca.crt;
ssl_verify_client on;
ssl_verify_depth 1;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;
location /error_serve {
root /sites/error;
error_page 400 402 403 404 = /error_serve/5xx.html;
}
location / {
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_pass http://192.168.1.1/;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
error_page 400 500 502 503 504 = /error_serve/5xx.html;
error_page 495 496 = /error_serve/cert_wrong.html;
}
}
All other error pages are working, only the 495 and 496 return the standard pages.
The SSL handshake happens before any HTTP request, so there is no known location at the time. In this case nginx just picks up configuration from the first one (which is location /error_serve in your configuration).
I have a wildcard DNS entry so *.mydomain.tld is directed to my server.
I'm Using nginx
I have 2 conf files titled:
default
myconf.conf
My conf files look like this:
default:
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
root /var/www/website;
index index.html index.htm;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
}
}
myconf.conf:
server {
listen 80;
#listen [::]:80 default_server ipv6only=on;
root /home/me/www/website;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
# orig # server_name localhost;
server_name me.mydomain.tld;
access_log /home/me/logs/me.mydomain.tld.access.log;
error_log /home/me/logs/me.mydomain.tld.error.log warn;
location / {
try_files $uri $uri/ $uri.php?$args;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
When I browse to the domains as follows, these are the conf files that load up.
me.mydomain.tld loads up root directory defined in myconf.conf
mydomain.tld loads up root directory defined in default
anything.mydomain.tld loads up root directory defined in myconf.conf
What is going wrong that default is not being the catchall it should be?
anything.mydomain.tld should be loading the root directory in the default conf file.
In your default config file, you have to specify default_server on both listen lines; also, you need to remove the server_name line:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/website;
index index.html index.htm;
#server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.html;
}
}
The underscore that you are using for the server_name is not actually a wild card (if that was your intent). From the nginx Server Names documentation:
There is nothing special about this name, it is just one of a myriad of invalid domain names which never intersect with any real name. Other invalid names like “--” and “!##” may equally be used.