Last active
August 11, 2022 03:02
-
-
Save kamrankr/12a05456df785e9604b1 to your computer and use it in GitHub Desktop.
how to configure Nginx for multiple domains and sundomains on Ec2 instance with default amazon ami
This file contains hidden or 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
server | |
{ | |
server_name mysite.com; #first domain | |
root /var/www/html; | |
index index.php index.html index.htm; | |
error_page 404 /404.html; | |
location / | |
{ | |
try_files $uri $uri/ /index.php?q=$uri&$args; # this rewrite rule is for wordpress blog | |
} | |
location ~\.php$ | |
{ | |
#fastcgi_pass unix:/var/run/php/php-fpm.sock; # uncomment if you are using socket | |
fastcgi_pass localhost:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
} | |
############################## For subdomain ######################################### | |
server | |
{ | |
server_name subdomain.mysite.com; | |
root /var/www/html/subdomainfolder/; | |
index index.html index.htm index.php; | |
location / | |
{ | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
location ~\.php$ | |
{ | |
fastcgi_pass localhost:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /var/www/html/api/public$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
} | |
############################## For another domain ################################# | |
server | |
{ | |
server_name anotherdomain.com *.anotherdomain.com; | |
root /var/www/html/anotherdomain.com; | |
index index.html index.htm index.php; | |
location / | |
{ | |
#try_files $uri $uri/ /index.php?$query_string; | |
} | |
location ~\.php$ | |
{ | |
fastcgi_pass localhost:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME /var/www/html/anotherdomain.com$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment