Last active
May 12, 2024 03:51
-
-
Save natanfelles/35302501ec70e2536725aa166d2cfa59 to your computer and use it in GitHub Desktop.
Nginx Virtual Host example to work on localhost
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Location: /etc/hosts | |
127.0.0.1 localhost | |
127.0.0.1 domain.tld |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Location: /var/www/domain.tld/public/index.php | |
phpinfo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Location: Anywhere | |
sudo ln -s /etc/nginx/sites-available/domain.tld.conf /etc/nginx/sites-enabled/domain.tld.conf; | |
sudo service nginx restart; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change domain.tld by your domain.
/etc/nginx/sites-available/domain.tld.conf
./etc/hosts
./var/www/domain.tld/public/index.php
.If anything do not work. Execute
nginx
on the terminal (as root) to see the error output.