cannot change the default port on nginx - nginx

I am using the nginx web server bundled with gitlab and I have SSL setup and I am using the non-default port i.e. I have the URL setup as
external_url 'https://www.myserver.com:2443'
However, when I connect with this address, I get a connection was reset error. Running, gitlab-cal tail shows
bind() to 0.0.0.0:80 failed (98: Address already in use)
I am not sure why it still is looking at port 80. Is there some other setting that I must set here.

Related

nginx forward a request with user name and password

I am trying to forward a post request that i get :
https://user:pass#somedomain.zz/abc/cccc
when i am trying to forward in nginx the request, and put a new url with the user name password the same way i got it nginx not allow me to put it in the conf.d folder and thinks its a port this is the error
nginx: [emerg] invalid port in upstream "zz:ff#newdomain.com" in /etc/nginx/conf.d/logs.conf:4 nginx: configuration file /etc/nginx/nginx.conf test failed

Nginx fails with port 80, but only when I am connected to the virtual server by SSH

I first opened a Linode.com droplet.
Then installed Nginx, and left the default configuration.
I pointed my domain to the droplet's IP address.
The command "systemctl status nginx" - shows an error, this one seems relevant:
"Jun 18 14:40:13 localhost nginx[25837]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)"
I searched and racked my brains out until I tried this:
change config file so that Nginx/website listens to port 8080
Working fine, I then changed settings back to port 80 (stopped working)
The process was not halted, so step 2 allowed me to run the command "Nginx -s reload" (the reload signal needs the process running, and I couldn't restart Nginx with systemctl due to the original error)
While the website was not loading, I exited the SSH connection (which I checked, was using port 22, not 80)
My website then started working!
Re-entered the droplet with SSH, and found Nginx listening on port 80 just fine.
I want to understand why this worked, as it makes no sense that port 80 should be unavailable to Nginx just because I have an SSH connection.
I don't think it's unique to Linode's configuration as I have a Digital Ocean droplet too, and this was failing to listen on port 80 as well, although I never tried the fix I discovered on Linode.

MAMP Pro nginx won't start

Last week I was able to use MAMP Pro on MacOS Big Sur 11.6 (Mackbook Pro M1) to run the nginx web server for multiple virtual hosts. Today, after using certbot locally in renewing my local LetsEncrypt SSL certificate that supports local dev https development, I cannot start nginx on any of the virtual hosts.
I get a warning in MAMP Pro that says "You configured nginx to use ports 80 and 443, but at least one of these seems to be in use." So I checked that MAMP is still configured to use port 80 for nginx. Then I used Activity Monitor to try to kill all httpd processes using port 80. Two of them, owned by root and _www, refused to die. So I used kill -9 with their respective PIDs. That killed them for a moment but they came back. After that, I tried to restart nginx again on port 80. It fails to start with message "Nginx couldn't be started. Please check the log file for more information."
The log file from that shows
2021/12/28 16:04:22 [emerg] 93920#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2021/12/28 16:04:22 [emerg] 93920#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2021/12/28 16:04:22 [emerg] 93920#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2021/12/28 16:04:22 [emerg] 93920#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2021/12/28 16:04:22 [emerg] 93920#0: bind() to 0.0.0.0:80 failed (48: Address already in use)
2021/12/28 16:04:22 [emerg] 93920#0: still could not bind()
How do I fully kill the root and _www user processes? More importantly, why is this happening? Was it something to do with the renewed LetsEncrypt SSL?
Support told me that this is a problem with MAMP Pro 5 on MacOS and that MAMP Pro 5 is no longer supported. Upgrading to MAMP 6+ solves the problem.

Nginx failed to bind and redirection

I'm trying to configure my reverse proxy through nginx using this tutorial, but when I go to restart the nginx server, it throws the following error message:
nginx[12681]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
I checked out the port using netstat, and I have the following result
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN off (0.00/0/0)
What does this mean? When I go to my domain name, it redirects to the Centos page instead of an nginx page I should be getting. How can I configure the file to get it to redirect to nginx?
Edit:
Added httpd status
httpd.service disabled
mysql.service enabled
my_api.service enabled
nginx.service disabled
I get the above errors when I try to start nginx using systemctl
Running netstat -luntp as root showed that nginx had spawned a master process and a worker. Killing those processes solved the issue

Nginx- error: bind() to 0.0.0.0:80 failed. permission denied

I am trying to run Nginx, but I am getting the error below:
bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a
socket in a way forbidden by its access permissions)
Please provide some help on what changes I need to do to make it working?
I have tried running on ports other than 80 and it works. but I need it to be running on 80.
Note: I am running on Windows 7 with command prompt running as Administrator.
If the port is already in use, you can change the default port of 80 to a different port that is not in use (maybe 8070). In conf\nginx.conf:
server {
listen 8070;
...
}
After startup, you should be able to hit localhost:8070.
tl;dr
netsh http add iplisten ipaddress=::
Faced similar issue. Run the above command in command prompt.
This should free up port 80, and you'd be able to run nginx.
Description:
netsh http commands are used to query and configure HTTP.sys settings and parameters.
add iplisten :
Adds a new IP address to the IP listen list, excluding the port number.
"::" means any IPv6 address.
For more netsh http commands refer the netsh http commands documentation.
Hope this helps!!
You have to be admin or root to bind port 80. Something you can do if you cannot run as root, is that your application listens to other port, like 8080, and then you redirect messages directed to 80 to 8080. If you are using Linux you redirect messages with iptables.
nginx: [emerg] bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)
I got a similar problem, My 80 port was listening to IIS (windows machine). Stopping IIS freed up 80 port.
The problem got resolved...!!
Please check if another Proxy is running under port 80 ---> in my case IIS was running as a reverse proxy, so nginx could not start..
Stopping IIS, and starting of NGXIN solved the problem
My Tomcat server was running on port 80. Changed the port number in conf\nginx.conf file and it started to work.
This is an old question but since I had this problem recently I thought of posting another possible reason in this problem.
If the user is using Docker and has already tried all proposed solutions as stated above and is wondering why port 80 is trying to bind although on your configurations you are overwriting the port to non root port e.g. listen 8080; it seems that the newer NGINX images have a default nginx.conf file in /etc/nginx/conf.d.
Sample:
$ grep -r 80 /etc/nginx/
/etc/nginx/conf.d/default.conf: listen 80;
On my case I removed it on my Dockerfile:
RUN set -x \
&& rm -f /etc/nginx/nginx.conf \
&& rm -f /etc/nginx/conf.d/default.conf
Next step pass from my custom configurations:
COPY ["conf/nginx.conf", "/etc/nginx/nginx.conf"]

Resources