Runcloud nginx try_files help!


#1

Can 2 try_files be present in a single location block?

Can I use break; or last; in location block? (not rewrite).

What I’m basically trying to do is:

location / {
    try_files $uri $uri/ =404; //How can i break here?
    try_files $uri $uri/ /index.php$is_args$args;
}

@itsbhanusharma


#2

You can safely remove this and handle 404 errors in php instead of nginx.

Here is a straightforward way to handle 404 in php


#3

That is not what I’m looking for. :confused:
I’m not using php but plain html. I wants to do it on server level.


#4

Can you describe what are you exactly aiming at?

EDIT:
Just for reference purposes,
http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files


#5

I use RunCloud to manage my server, I’m trying move to Native NGINX.

RC ads this config in server block.

location / {
    include /etc/nginx-rc/extra.d/app-heathcote.location.root.*.conf;
    try_files $uri $uri/ /index.php$is_args$args;
}

But I’ve problem with it. The problem is:

try_files $uri $uri/ /index.php$is_args$args;

This basically tells nginx if a non-exits directory/files found move the request to index.php

Now, this trouble for me. I don’t want to redirect non-exits page/file to index.php
I wants to throw 404.

Now, I can basically edit that line with this line:

try_files $uri $uri/ =404;

This is gonna solve my problem. But I don’t want to edit main.conf, because it is not recommended. But the recommended way to do is by adding rules in this file:

/etc/nginx-rc/extra.d/app-heathcote.location.root.*.conf;

How can I accomplish this?


#6

What are the contents of


#7

The break; and last; only works in rewrites not on a location block.


#8

Empty.

If I wants to add custom rules, I can create a file and add those rules in there.


#9

For example:

I can create

/etc/nginx-rc/extra.d/app-heathcote.location.root.extra-rules.conf;

Those rules will be included in the location / block. Because of this line:

include /etc/nginx-rc/extra.d/app-heathcote.location.root.*.conf;


#10

if nginx is handling just one website then there is no need to do the 404. You can maybe intercept errors and set error pages accordingly?

e.g.:

location ~ .php {
error_page /404.html
}


#11

I’m not using php. vanilla html.


#12

If that’s the case then,

Remove this and use the 404 block and it’ll be just fine for you.


#13

I can remove it. But removing will cause trouble in the future. Becuse runcloud cleary mentioned when the rc-agent-bot gets updated all the modification will be wiped out.

That’s why I don’t wanna edit the main.conf.

I need to find a different approach, without modifying main.conf


#14

You’re moving to native nginx right?

why will you configure runcloud nginx when you’re already going to take matter in your own hands?


#15

I’m not. I’m not leaving RC. RC is more than just a stack.


#16

Are you really?

If not then contact runcloud support to give you some sort of resolution. I don’t know how it works.


#17

it works the same way nginx works.


#18

Nginx doesn’t override their configurations over updates :slight_smile:


#19

Nope. But runcloud’s agent does. The agent is just a handler. They do things on our behalf.

I know you hate RC, SP. But not everyone is linux-friendly. I hate using terminal. I try to avoid as much as possible.


#20

See, Let’s get things clear.
I’m not hating their service but none of my recommendations are going to work for you because they don’t let configs remain there. If you are using standard nginx, that doesn’t happen at all and if nginx is not overriding the configs then you have to stop the 3rd party doing it. I don’t have a soultion for a nginx problem that isn’t being caused by nginx.