Question

Correct moving locations in default Nginx to separate files

Hello

I have a lot of location routings inside my default Nginx default file. I decided to move some of them based on the application that use them in separate .conf files. The problem is that when I transfer locations to the separate files and include them info the default files nginx does not restart

Main file :


server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name xxxx www.xxx;


    ssl_certificate /etc/xxxx;
    ssl_certificate_key /etc/xxx;

    # Include the SSL configuration from cipherli.st
    include snippets/ssl-params.conf;
    

    include /etc/nginx/conf.d/*.conf;

	
    location / {
				xxxx
        proxy_pass http://localhost:5000/;
				xxxx
    }
}


The sample.conf file

location /test/ {       
		xxxx
      proxy_pass http://localhost:7000/

    }

    location /test2/ {
      proxy_pass http://localhost:8000/;
    }
    

    location /sam/test3 {
      return 301 /sam/test2/;
    }

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

Whare is the sample.conf file located at?

I could suggest doing the following:

  • First create a new directory where you would keep your include files:
mkdir /etc/nginx/include
  • Then in your server block include all conf files from that directory with the following line:
include include/*.conf;

If you are still seeing that issue, you could run an Nginx config test:

sudo nginx -t

Feel free to share the output of the config test here so I could try to advise you further.

Best,

Bobby