Change Nginx Port on macOS Guide | Generated by AI

Home 2025.10

You want Nginx on macOS to listen on a different port than its default (80 for HTTP, 443 for HTTPS). Here’s a clear step-by-step guide:


1. Locate your Nginx configuration file


2. Edit the listen directive

  1. Open the config in a text editor:

    nano /opt/homebrew/etc/nginx/nginx.conf
    
  2. Find the server block:

    server {
        listen 80;
        server_name localhost;
    
        location / {
            root   html;
            index  index.html index.htm;
        }
    }
    
  3. Change listen 80; to your desired port, e.g., 8080:

    listen 8080;
    

3. Test the configuration

Run:

nginx -t

4. Restart Nginx

brew services restart nginx
sudo nginx -s reload

5. Access via new port

http://localhost:8080

Extra Notes:


I can also give a quick trick to temporarily run Nginx on any port without editing nginx.conf using a command line flag. It’s handy for testing. Do you want me to show that?


Back Donate