Skip to content

Instantly share code, notes, and snippets.

@natanfelles
Last active May 12, 2024 03:51
Show Gist options
  • Save natanfelles/35302501ec70e2536725aa166d2cfa59 to your computer and use it in GitHub Desktop.
Save natanfelles/35302501ec70e2536725aa166d2cfa59 to your computer and use it in GitHub Desktop.
Nginx Virtual Host example to work on localhost
# Location: /etc/nginx/sites-available/domain.tld.conf
server {
listen 80;
# listen 443 ssl;
# include snippets/snakeoil.conf;
root /var/www/domain.tld/public;
index index.html index.php;
server_name domain.tld www.domain.tld;
location / {
try_files $uri $uri/ /index.php;
}
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
location ~ /\. {
deny all;
}
}
# Location: /etc/hosts
127.0.0.1 localhost
127.0.0.1 domain.tld
<?php
// Location: /var/www/domain.tld/public/index.php
phpinfo();
@natanfelles
Copy link
Author

natanfelles commented May 7, 2016

Change domain.tld by your domain.

  1. Create the virtual host file like this: /etc/nginx/sites-available/domain.tld.conf.
  2. Edit your hosts file in /etc/hosts.
  3. Create the index file to test the configurations like: /var/www/domain.tld/public/index.php.
  4. Create the symlink to enable the virtual host then restart nginx server.

If anything do not work. Execute nginx on the terminal (as root) to see the error output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment