NGINX not serving from localhost but is serving from 127.0.0.1 - macos

I've set up a new macbook pro with El Capitan, I used homebrew to install everything. Also using brew services to start and stop launchctl.
I'm not sure what the problem is, I have it working on my iMac and did the same thing on the MBP, the config file is untouched, so I should be getting the default welcome screen on localhost, server_name is set to localhost
Any suggestions?

So the fix was adding [::]:8080 to the nginx.conf file
I used sudo lsof -i TCP -Pn | grep nginx and saw it
was listening for ipv6 like #ZYWJ was hinting at.
So your nginx.conf file should look something like this:
server {
listen [::]:8080;
server_name localhost;
}
I installed with homebrew
I hope this helps anyone with the same problem.

Related

Macbook M1 Apache seems to be always running

It seems like there's some kind of apache is always running on my Macbook with M1 Pro chip. It always shows "It works!" page on by the localhost address with no ability to change it. Even if I run sudo apachectl stop - it's still running, taking my 80 port. Can I stop it somehow? I can't really create any virtual host because of that
In a terminal, type
sudo lsof -i -n -P | grep TCP
find out which app (may not be the Apache Server) is listening on TCP 127.0.0.1:80 and then stop/kill it.

Using dnsmasq with wildcard on Mac

I'd like to point all *.test domains to my Laravel Homestead machine on 192.168.10.10. I used to have it working with *.dev domains, but after new *.dev policy implemented by Chrome 63, I prefer to change it to *.test.
I fail to understand how local DNS works, as it seems to use trillion different configs and caches. What I did is:
Making sure 192.168.10.10 with HTTP Host set to me.test works. It works.
In /usr/local/etc/dnsmasq.conf, I do have an entry address=/.test/192.168.10.10 (I also tried with 127.0.0.1)
In /etc/resolver/test file, I put nameserver 127.0.0.1 - it used to work this way with /etc/resolver/dev. I still don't understand why it's 127.0.0.1 and not 192.168.10.10. I tried both anyway.
Clearing DNS cache with sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache
Restarting dnsmasq with sudo launchctl stop homebrew.mxcl.dnsmasq; sudo launchctl start homebrew.mxcl.dnsmasq.
Trying to visit http://me.test/.
It doesn't work. The domain will take forever to be loaded and nothing happens.
What am I doing wrong?
My OS is High Sierra, dnsmasq installed via homebrew.
I don't use dnsmasq, but I believe you want to edit /usr/local/etc/dnsmasq.conf and have listen-address=127.0.0.1 set so dnsmasq is listening on that IP, but have address=/.test/192.168.10.10 so that .test is routed to 192.168.10.10.
Then make sure System Preferences -> Advanced you have 127.0.0.1 as the first DNS server entry for your connection.
Make sure you're restarting dnsmasq every time you edit the configuration file.

Killing an unknown self restarting server on port 80 Mac OSX

I have a server running on port 80, but I do not know what it is or where it came from. When I run
sudo lsof -i :80 | grep LISTEN
I get
httpd 80 root 5u IPv6 0x91f5a9de62859cfd 0t0 TCP *:http (LISTEN)
httpd 694 _www 5u IPv6 0x91f5a9de62859cfd 0t0 TCP *:http (LISTEN)
I have tried to enter get the process name using the PID, but all I ever get in return is "httpd" or "FOREGROUND".
When I kill the PID, the process simply restarts with a new PID. I assume I will have to stop it at launch.
How can I stop this server from running at startup?
If it helps any, I am trying to free up port 80 to use the apache server on MAMP.
This is just a guess, but it might be the built-in version of apache, being launched (& restarted) by launchd (OS X's daemon manager). It's disabled by default, but might've gotten enabled somehow. You can try disabling it with:
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
If that doesn't do it (it'll say something like "Could not find specified service"), you can check to see if it's some other launch daemon item by looking for the PID of the master process (the one running as root, not _www):
sudo launchctl list | grep <masterPID>
That won't necessarily tell you exactly what's going on, but might point you in the right direction.
Like Gordon suggested, that's the built-in version of the Apache web server.
You can stop it with
sudo apachectl stop
btw, the configuration for this webserver can be found in the /etc/apache2/httpd.conf directory.
This happens to me a lot.
As #Gordon Davisson explains it is most likely the launchdeamon process conflicting with the service you have set up.
Definitely stop the apachetl server.
sudo apachetl -k stop
Try to find all the httpd process, they should be the last ones
sudo lsof -i :80 // without grep
Then get the first process (most likely in the 1000s) should also be the lowest one.
sudo kill <firstHttpdPID>
This should kill ALL the processes running that httpd instance and then you get simply start back up your server.
Must stop it first though or it will continue running again.
Mac OSX comes bundled with Apache, however it is deactivated. You might have activated it somehow. In my case, I have previously install XAMPP and configured something in the /etc/apache2/httpd.conf that leads my port localhost:80 to leads to html page with It Works!.
TLDR, the solution is to deactivate the Apache2 server.
Go to your terminal, and type this
sudo apachetl -k stop
In my case, it returns the following:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Shafies-MacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message
httpd (no pid file) not running
if you typed localhost on your browser, the port 80 is not active anymore and you will not see It Works! anymore.
For context, I have deleted XAMPP long time ago and not aware that my localhost:80 is still active. I am not able redirect dummy domain -- posts.com to my localhost port for my kubernetes YAML config files.
This is my ingress-srv.yaml file:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-srv
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: 'true'
spec:
rules:
- host: posts.com
http:
paths:
- path: /?(.*)
backend:
serviceName: client-srv
servicePort: 3000
and I have tricked the operating system to redirect my posts.com to localhost:80 by adding below line in the hosts file located at /etc/hosts
127.0.0.1 posts.com
by SM

Why would apache refuse connection to localhost 127.0.0.1 on OSX?

When trying to access sites on my localhost the connection is refused. Two days ago the set up was working without issues with multiple virtual hosts configured. I'm not aware of any changes that could have affected the set up. I spent all day yesterday trying to troubleshoot the issue but have been going around in circles.
OS: OSX 10.11.16
httpd -V returns this:
Server version: Apache/2.4.18 (Unix)
Server built: Feb 20 2016 20:03:19
Server's Module Magic Number: 20120211:52
Server loaded: APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_FLOCK_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/usr"
-D SUEXEC_BIN="/usr/bin/suexec"
-D DEFAULT_PIDLOG="/private/var/run/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="/private/etc/apache2/mime.types"
-D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"
httpd.conf is configured to allow virtual hosts and nothing has changed in httpd-vhosts.conf file.
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
...
# Virtual hosts
Include /private/etc/apache2/extra/httpd-vhosts.conf
apachectl configtest returns:
Syntax OK
I've tried running a port scan for 127.0.0.1 and http port 80 does not show. This and the connection being refused makes me think this is where the issue is but I don't know why. The OSX firewall is turned off. I've tried the solution posted here but it did not fix it.
My /etc/hosts file looks like this:
#
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
#
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 site.local
127.0.0.1 othersite.local
...
I can ping 127.0.0.1. I previously had homebrew installed to run different PHP versions but I've removed that to try and bring the system back to stock. I really don't know what to try next, any help would be really appreciated.
It happened to me while upgrading php. Below steps worked for me to bring me back on track.
Generally, mac creates a back-up before upgrading. Hence, we'll be using the pre-update version of httpd.conf
cd /etc/apache2/
sudo mv httpd.conf httpd.conf-afterupdate
sudo mv httpd.conf.pre-update httpd.conf
sudo apachectl configtest
sudo apachectl restart
You could check to ensure you have Listen: 80 in your /usr/local/etc/apache2/2.4/httpd.conf configuration file.
After several days of trying to debug this I resolved it by overwriting my httpd.conf file with an older one that was created when upgrading to osx elcapitan.
sudo cp httpd.conf~elcapitan httpd.conf
After doing this localhost was accessible again. I don't know what was wrong with my previous httpd.conf file. I'd been through it many times looking for issues and never found any. I even diffed the two files to try and see where the problem was and found no reason why it would fail in the way it was.
Once I had localhost responding again I went through the process of enabling the modules I require and reconfiguring my virtual hosts.
Again, I don't know what was wrong with the other httpd.conf file. Perhaps it was corrupted in some way. Regardless it was failing silently with apachectl configtest not reporting any problems.
So if others have a similar issue it may be worth reverting back to an older httpd.conf file. OSX usually creates a backup when upgrades are done.
In my case DocumentRoot in the httpd.conf file was wrong.
I figured it out after typing httpd in the terminal. Try the same maybe it can give you some hints to solve the problem.
➜ ~ httpd
AH00526: Syntax error on line 255 of /usr/local/etc/httpd/httpd.conf:
DocumentRoot '/Users/xx/Desktop/sites' is not a directory, or is not readable

Nginx El Capitan ERR_CONNECTION_REFUSED

I Have installed Nginx-full via homebrew to the latests stable 1.8.1 version. I have installed php7.0 via brew as well. I want to get php working but i can't first get nginx to serve a static file. I have this configuration on a server and works perfectly but on my mac I'm having trouble. I set up my sites directory as follows:
nginx.conf:
#user www-data www-data;
worker_processes 4;
events {
worker_connections 1024;
}
http {
include mime.types;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
/sites-available/default
server {
listen 80;
server_name localhost;
root /Users/londreblocker/Developer/Sites/bootstrap;
index index.php
error_log /Users/londreblocker/Logs/DMFA_erros.log;
access_log
/Users/londreblocker/Logs/DMFA_access.log;
}
there is a symbolic link to default in the sites-enabled folder. When i try to connect all i get is
This webpage is not available
ERR_CONNECTION_REFUSED
Any idea what could be going wrong. I am on a mac with El Capitan.
Check if nginx configuration is correct:
sudo nginx -t
and your config symlinks not broken:
ls -al /etc/nginx/sites-enabled
Check if nginx running:
ps aux |grep nginx
Check if nginx listening port 80:
sudo lsof -i -P | grep -i "listen"
If anyone is interested in my solution.
I had more than one version of nginx running due to previous install attempts and incorrect uninstalls. I deleted all versions and then did a reinstall. Seems to be working now.

Resources