I want to add this extra config to my nginx.conf:
server {
listen 0.0.0.0:8081;
rewrite ^ https://$host$request_uri? redirect;
}
But as my app is deployed in a hosting service I don't want to modify the already present nginx.conf
. It can be problematic.
Is there any way I can add this extra configuration without modifying nginx.conf?
If you are using a dedicated server / VPS and want to host multiple applications on a separate domain and a single server then you will need to host multiple websites on a single server. You can achieve this with Apache / Nginx virtual hosting. Virtual hosting allows you to use a single VPS to host all your domains.
NGINX Plus adds additional methods for modifying configuration dynamically. By using DNS as the definitive repository for upstream servers, you can make changes without touching NGINX Plus configuration files.
You need to reload or restart Nginx whenever you make changes to its configuration. The reload command loads the new configuration, starts new worker processes with the new configuration, and gracefully shuts down old worker processes.
There is no way you can add extra server configuration without modifying nginx.conf
first. But good news is that you will have to modify nginx.conf only for once.
Just add this line in your nginx.conf
include /etc/nginx/config.d/*.conf;
You can name directory and path as per your choice.
create directory and save your extra configuration in that as extra.conf
with .conf
extension. Any files you save with .conf
extension in this directory /etc/nginx/config.d
will be automatically added to your nginx.conf.
You can even save multiple configurations like extra1.conf
and extra2.conf
for different uses and you can delete one without affecting other.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With