For the last month I tried learning how to create subdomain on centos, nginx, php,mysql. But I still could not get it to work.
I want to create a few subdomain with subdomain directory in the domain root folder. With my vhost.conf file below, my subdomain only works with index.html, but not index.php. I test and test but could find a way to make auto subdomain to works with index.php. BUT my index.php work with domain and not subdomain. PLEASE HELP...just about to give up...
MANY THANKS,
=======net.com.conf=====
server {
listen 80;
server_name www.net.com;
root /var/www/public_html/net.com/public/;
index index.php index.html;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
include /var/www/public_html/net.com/public/nginx.conf;
location ~ /nginx.conf {
deny all;
access_log off;
log_not_found off;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
root /var/www/public_html/net.com/public/;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/public_html/net.com/public/$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80;
server_name ~^(.*)\.net\.com$;
#if directory doesn't exist
if (!-d /var/www/public_html/net.com/public/$1) {
rewrite . http://www.net.com/ redirect;
}
index index.php index.html;
# Sets the correct root
root /var/www/public_html/net.com/public/$1; <---IS THIS CORRECT
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
root /var/www/public_html/net.com/public/$1; <<-----IS THIS CORRECT?
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/public_html/net.com/public/$1$fastcgi_script_name;<<<--- THIS CORRECT?
include fastcgi_params;
}
}
}
server {
listen 80;
server_name net.com;
rewrite ^/(.*) http://www.net.com/$1 permanent;
index index.php index.html;
}