nginx virtual host - fail when restart with no error - nginx

I have several subdomains running on nginx, and when i added next one, there was a problem with the same name of subdomain i removed.
I'm not shure that config were worked in the past. This is what i have found on serwer.
For now there is no possibility to restart nginx with virtual hosts, becouse it's failed.
config tests is ok,
without vh's it is restarting well,
nginx.conf test is ok,
logs are clear
nginx config is placed in project and /etc/nginx is pointing to that folder
I have add that exaple vh and it is crushing event with it.
What else can i check, what may cause such a problem?

I have found solution. Nginx could not start after stop, becouse ports 80 and 433 were busy by... nginx. Anyway
netstat -tulpn
shown what process are runing on particular ports.
I killed these processes with commands:
sudo fuser -k 80/tcp and fuser -k 433/tcp
and after that
sudo service nginx start
just worked.
Config files are fine, and test pass, logs where clear and nginx command show whats wrong

Related

Node js Application running on EC2 but not accessible in browser using Nginx

I'm a newbie to Nginx. I cannot access my Node.js application that I deploy on AWS EC2 using Nginx reverse proxy. If I do curl http://localhost:3000 I can see the application is running successfully on the server(I'm using pm2 for running node server). But when I try to access it in my browser or postman using public DNS I get the error This site can't be reached and the request gets timeout. Here's my Nginx configuration (I have followed a number of tutorials for this)
The configuration file is named nginx.conf and is in /etc/nginx/sites-enabled directory. If I do sudo nginx -t it says syntax is ok and the test is successful. Also I can see the Nginx is running using command sudo systemctl status nginx What could be the possible reason for this behaviour?
I figured it out the problem wasn't with the Nginx configuration actually I needed to allow public access for port 80 on my ec2 instance which is blocked by default. I allowed port 80 and everything is working fine. This blog helped me. Visit it for me details on how to enable port 80 for your ec2 instance.

nginx config does not update after reload

following this tutorial :
https://www.digitalocean.com/community/tutorials/how-to-redirect-www-to-non-www-with-nginx-on-centos-7
I modified my config file /etc/nginx/sites-available/domainName by adding on the last row :
return 301 $scheme://www.example.com$request_uri;
Then I launched :
sudo systemctl restart nginx
It works well. Then I tried to modify www.example.com by my domain name and I launched again ;
sudo systemctl restart nginx
but it doesn't work, I'm still redirecting to example.com
I checked the log files, sudo nginx -t etc and everything looks good.
Do you have an idea of the problem?
Thanks
Try clearing the DNS cache in your pc, browser, and router.
If you're using Windows to run a Linux server in a virtual box, you can run the ipconfig /displaydns command to see the time of cache to live.

What's the difference between starting nginx with command "nginx", "service start nginx" and "systemctl nginx start"?

I have noticed that when ever I start nginx with ubuntu command "nginx" and I do systemctl status nginx. It shows that systemctl is disabled. More over if I first start nginx with command systemctl start nginx and i try to start nginx with command nginx, it check the availbility of the ports and then says nginx: [emerg] still could not bind(). So i thought there must be a differene and their purpose. When I strt nginx with command nginx the only way to stop nginx is by the means of force using killlall nginx or kill -9 (process id) or by clearing the port. So I am pretty sure there is some difference in them.
The difference between the examples you have provied is how the processes are being started.
Running the command nginx will start the application and wait for your user action to stop it.
The systemctl or service commands are nearly the same thing and running service nginx start or systemctl start nginx will start a service in the background running the Nginx daemon.
You can also use this to do a service nginx restart or systemctl restart nginx to restart the service, or even a service nginx reload / systemctl reload nginx to reload the configuration without completely stopping the Nginx server.
The reason why you can't do both nginx and systemctl start nginx is due to the nginx configuration already listening port 80, and you can't listen on the same port on a single IP address at the same time.
You can also force the nginx service to start on boot by running systemctl enable nginx which will be why your systemctl status nginx returns 'disabled'.
Hope this makes sense.
service command is just a simple script which basically abstract choosing the underlying init system (upstart, systemmd , /etc/init.d or systemctl).
since it being a very concise script, it only supports a very limited set of operations (start | stop | reload .. ).
However, if you actually want to perform the additional operation you need to make use of the actual init system in this case systemctl
An apt example would be starting the service on boot time using systemctl sudo systemctl enable the-name-of-service which is not possible using service

Finding 'Nginx.conf'

I recently started using vagrant and Virtualbox to run my Wordpress website. Today I ran into a problem. I was trying to import a theme and this happened.
413 Request Entity Too Large --- nginx/1.6.2 (Ubuntu).
I think that I know how to solve this, but for that i need to have access to the nginx.conf file. How do I access this where do I find it?
I' m using a mac.
you would need to login into the VM - you can do vagrant ssh to do so.
Once on the VM, you would need to edit your nginx.conf file as sudo (nginx.conf file is generally located in the directory /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx on your VM depending how the installation was done) so sudo vi nginx.conf from the correct directory and you can make the change.
make sure to restart nginx after you made the change sudo /etc/init.d/nginx restart from the VM or even restart the VM if you make many changed vagrant reload from the host and you'll be ok

Stopped Nginx still allows root index.html access

I'm brand new to Nginx. But after running
sudo /etc/init.d/nginx stop
and got
Stopping nginx: [OK]
I can still browser index.html from outside ip.
How can I really/completely stop Nginx server? Thanks a lot!
sudo /etc/init.d/nginx stop
will do the trick

Resources