Skip to content

Instantly share code, notes, and snippets.

@WalterWoshid
Last active February 17, 2023 14:52
Show Gist options
  • Save WalterWoshid/eeb5dab6e9e6ddfd9ce54dbcc409ddcc to your computer and use it in GitHub Desktop.
Save WalterWoshid/eeb5dab6e9e6ddfd9ce54dbcc409ddcc to your computer and use it in GitHub Desktop.
Add "server_name localhost;" to nginx config script

Add Server Name (nginx)

Twitter: @WalterWoshid

Whats the point of this script?

When we setup our project with docker, this line is missing in the nginx config. The xdebug extension in combination with PhpStorm doesn't recognize the connection without "server_name localhost".

We also call a powershell script to execute the script inside the container like this:

docker-compose exec -u root app /bin/sh -c bin/add_server_name.sh
#!/bin/sh
# "listen 8443 ssl http2;" is the part after which it gets placed
echo "$(awk '/server_name localhost;/{found=1; next}; /listen 8443 ssl http2;/{print $0 "\n server_name localhost;"; next}; {print}' /etc/nginx/conf.d/default.conf)" > /etc/nginx/conf.d/default.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment