Installed nginx and php-fpm via Homebrew.
I've disabled native Apache 2.4 that comes with OSX by running:
glfx:~ glfx$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
It even says it's not running anymore:
/System/Library/LaunchDaemons/org.apache.httpd.plist: Could not find specified service
Then I run my nginx and check what's bound to my port 80:
glfx:~ glfx$ lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 266 glfx 9u IPv4 0x6267c63df8016e53 0t0 TCP *:http (LISTEN)
nginx 267 glfx 9u IPv4 0x6267c63df8016e53 0t0 TCP *:http (LISTEN)
nginx 268 glfx 9u IPv4 0x6267c63df8016e53 0t0 TCP *:http (LISTEN)
nginx 269 glfx 9u IPv4 0x6267c63df8016e53 0t0 TCP *:http (LISTEN)
nginx 270 glfx 9u IPv4 0x6267c63df8016e53 0t0 TCP *:http (LISTEN)
nginx 271 glfx 9u IPv4 0x6267c63df8016e53 0t0 TCP *:http (LISTEN)
nginx 272 glfx 9u IPv4 0x6267c63df8016e53 0t0 TCP *:http (LISTEN)
nginx 273 glfx 9u IPv4 0x6267c63df8016e53 0t0 TCP *:http (LISTEN)
My nginx configs are:
worker_processes 8;
user glfx staff;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "http_x_forwarded_for"';
access_log logs/nginx/access.log main;
error_log logs/nginx/error.log debug;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
gzip on;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_proxied any;
server_names_hash_bucket_size 128;
server_names_hash_max_size 20000;
proxy_headers_hash_bucket_size 128;
proxy_headers_hash_max_size 20000;
underscores_in_headers on;
include /usr/local/etc/nginx/sites/*;
}
And site config:
server {
listen 80;
server_name signals.dev;
root /Users/glfx/Projects/signalsplatform.dev/public_html;
access_log /usr/local/var/log/nginx/signals.dev.access.log;
error_log /usr/local/var/log/nginx/signals.dev.error.log;
rewrite ^/app_dev\.php/?(.*)$ /$1 permanent;
location / {
index app_dev.php;
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /app_dev.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
root /Users/glfx/Projects/signalsplatform.dev/public_html;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
When I try to access signals.dev in my browser – No connection to the web server at all, though signals.dev:8080 is giving me Nginx 404 not found.
Why I can't bind my nginx to use 80 port?
Best Answer
You have to use sudo to bind any port below 1024, privileged ports. i will try to sum up all. first disable internal apache by adding disabled to file /System/Library/LaunchDaemons/org.apache.httpd.plist
then copy nginx's plist file to /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
with this parameters. check the plist file ownership. which has to belong root:wheel
then you can start nginx with privilege to bind port 80 & 443.
PS: you can use lunchy (a simple ruby app to manage launchctl.) which is perfect for this job. like: sudo lunchy edit apache, sudo lunchy start nginx etc.
Also you can see what is wrong while playing launchctl with syslog -w command.