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.
Related
I have hosted my JavaScript application in aws ec2 server. I'm using centos 7 and placed my JavaScript static files in /usr/share/nginx/html directory. I'm using nginx as reverse proxy.I have one yaml file inside this JavaScript files that is accessible through the browser. The yaml file contains all the sensitive information but that file is necessary to load my application. Is there any way to disable direct access to that file in browser. Or is there any way to disable that information disclosure in browser through nginx.Thanks in advance for the help.
I have tried
location /properties.yaml {
rewrite ^/$ /login.html permanent;
}
But this is not working. Then i tried to read that file from other location like
location /properties.yaml{
try_files $uri /var/www/html/properties.yaml;
}
Could you please guide.
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".
I have app on Node.js on Nginx.
When I open page
domainname.com/somefolder/page.html
it should show in address bar the same page
domainname.com/somefolder/page.html
But page.html can be on the page deep in folder like
morefolder/anotherfolder/…./somefolder
Meanwhile I have folders, which are located in core folder and should open from this folder. How to solve it?
You can achieve it by configuring nginx as below:
server {
listen 80;
server_name domainname.com www.domainname.com;
#root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /somefolder/page.html {
root morefolder/anotherfolder/onemorefolder;
}
}
Your core folder is morefolder/anotherfolder/onemorefolder
All subfolders and html pages are within.
You browse domainname.com/somefolder/page.html it re-directs it to domainname.com/morefolder/anotherfolder/onemorefolder/somefolder/page.html but this is transparent to user and address bar shows same page you browsed.
Since I don't have exact name of files and folders I used this construction
location / {
try_files $uri /post$uri =404;
}
location / checks any URL which is not specified (i.e. domainname.com/test). In my case it was any URL like domainname.com/folder/file.html
try_files checks URL (aka $uri) and if it is not found then goes to next /post$uri and if it's not found, then shows 404 page
In my case i open page www.domainname.com/folder/file.html it checks whether it exists, it doesn't exist, then it checks whether www.domainname.com/post/folder/file.html exist and opens it if it exist, otherwise shows 404 page
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!
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