How to fix nginx conf for static site? - nginx

I don't understand why my nginx.conf file does not work.
This is just supposed to serve a static web site.
Later I want to add a wordpress to /blog.
Currently I want to make the main static site work.
The related conf is this:
location / {
index index.html
root /var/www/html/xlanding;
try_files $uri $uri/ =406;
}
This nginx is dockerized. I log in to the docker container and I can confirm that /var/www/html/xlanding/ exists and there is an index.html file there.
When I visit the url I see a 406 error (just changed from 404 to confirm that block is entered). So the block is matched.
How can I fix this?

Ah, I missed a semicolon after the "index index.html".

Related

How make Wordpress overrides URL in nginx

I have the current syntax in my nginx server block in /sites-available/:
location / {
try_files $uri $uri/ /index.php?$args;
}
Actually i have a WordPress installation in my root folder. And I have some folders mixed in the root folder too. So looks like these:
https://mywebsite.com/mycustomfolder/foo/bar/ <- WordPress URL
https://mywebsite.com/mycustomfolder/ <- Folder with simple HTML files
I need to access both of the cases. But the nginx is forcing somehow to just access /mycustomfolder/ who have no files and I get a 403 Forbidden or I access the files normally if have them.
So, what I desire is, if there is no files or folder, just keep WordPress show a 404 page or a custom created. And if there is files or folder, show them as HTML/PHP normally.

nginx how to serve pictures or media files?

I'm having issues serving pictures with nginx. I originally started with a Django project and I wanted to serve the user uploaded media files via nginx but I wasn't able to get it working no matter what I tried.
So, I've make a second temporary droplet/server and am trying a bare bones setup with no Django project, just Nginx, to see if I can get it to simply serve an index and a couple pictures in a folder called 'media'. Here is the server block:
server {
listen 80;
listen [::]:80;
root /var/www/example.com/html;
index index.html;
server_name 159.89.141.121;
location / {
try_files $uri $uri/ =404;
}
location /media/ {
root /var/www/example.com/media;
}
}
Now, the index.html is served fine but if I try to go to 159.89.141.121/media/testpic.jpg it still doesn't work and returns a 404 error. I'm at a complete loss here, I've tried using alias instead of root, I've tried changing the folder structure and setting all permissions to 777 and changing folder and file ownership, permissions shouldn't be a problem because the index.html works fine with the same permissions; I just cant seem to figure out what I'm doing wrong. The picture is in the folder but nothing I try allows me to access it via the uri. Are there any obvious problems with my server block?
Well I decided to read the documentation and realized that the location block adds to the root directory specified..
So the pathing of
`location /media/ {
root /var/www/example.com/media;
}`
would end up routing example.com/media/testpic.jpg to /var/www/example.com/media/media/testpic.jpg
I've changed the location block to look like this
location /images/ {
root /var/www/example.com/media;
}
and it will now route example.com/images/testpic.jpg to /var/www/example.com/media/images/testpic.jpg
I'm not sure why it didn't work when I tried the alias directive, though...

NGINX Wordpress install in subdirectory wrong script URL

Switching from Apache to NGINX here :)
So I have Site A which sits on the root directory http://test.fake.com/ and works fine. I also have another Wordpress Site (B) where the root is http://test.fake.com/b/
All the front end pages for B load scripts and css like http://test.fake.com/test.fake.com/b/ which of course is incorrect. When I try to goto the Admin like http://test.fake.com/wp-admin/ I receive No input file specified. as the only output, also the URL changes to http://test.fake.com/test.fake.com/b/wp-login.php.
Here is a snippet of my NGINX config where I think the problem lies, please let me know if you need more info and be gentle on a NGINX n00b :P
location /b {
try_files $uri $uri/ /b/index.php$args;
}
location / {
# Set try_files according WP architecture
try_files $uri $uri/ /index.php$args;
}
Here is a snippet of B's wp-config file where I am setting the URLs
define('WP_HOME','http://test.fake.com/b');
define('WP_SITEURL','http:/test.fake.com/b');
I have no idea where the error lies :(
Thank you for viewing!

NGINX Server block when MediaWiki in subdirectory

MediaWiki installation was in domain.com/subdirectory and worked with Apache as the server.
Pages were found domain.com/subdirectory/index.php/Main_Page
The server was changed to NGINX the other night. WordPress and XenForo work fine but the location block for MediaWiki isn't working properly.
Since I'm new to NGINX and the configuration file inner workings, I'm not sure how to write the location block to get the results equal to the Apache page layout (index.php shows).
This is my latest attempt (failed, of course).
#MEDIAWIKI
location /subdirectory/ {
try_files $uri $uri /index.php?query_string;
}
This writes to domain.com/subdirectory/title and the index.php is missing.
The documents show writing to a subdomain and this is not what I'm wanting. The index.php also needs to remain.
Thank you for providing as much information so this is solved. For example, I'm not sure if LocalSettings needs modification.
Try adding
index index.php index.html;
Updated*
location /subdirectory/ {
index index.php index.html;
}
Using Rewrite
rewrite ^ /index.php?$request_uri;
this will forward requests to /subdirectory/index.php?
In your case, /subdirectory/index.php?/Main_Page

Nginx Static Configuration - Misdirected

Nginx pointing to the static directory
I can’t figure out where I am going wrong here. I am trying to point Nginx to my static directory for the CSS and JS.
The true location of my static folder is as follows:
/var/www/site/app/static
/var/www/site/app/static/js
/var/www/site/app/static/css
In my app_nginx.conf I have this:
location /static {
root /var/www/site/app/static;
index index.html;
}
When I go to my site it is looking for the content in this folder:
http://localhost/static/css/main.css
Where am I going wrong here?
You should be able to use something similar to the following.
root /var/www/site/app/static;
location / {
index index.html;
}
Then you should be able to use the following url to hit your content
http://localhost/css/main.css
I corrected this, you shouldnt include the static folder in the root directive, it should have been like this:
root /var/www/site/app;

Resources