Nginx 多域名同 IP 设置

/

/etc/nginx/nginx.conf

...

http {
    ...    
	
    # www.domain1.com
    server {
			server_name domain1.com;
			return 301 $scheme://www.domain1.com$request_uri;
    }

    server {
            server_name www.domain1.com;
            root /var/www/domain1.com;
            index index.php index.html index.htm;
            include /etc/nginx/sites-enabled/domain1;
        }

	# domain2.net		
    server {
            server_name www.domain2.net;
            return 301 $scheme://domain2.net$request_uri;
    }

    server {
            server_name domain2.net;
            root /var/www/domain2.net;
            index index.php index.html index.htm;
            include /etc/nginx/sites-enabled/domain2;
    }

    ...
}

...

/etc/nginx/sites-available/domain1 or /etc/nginx/sites-available/domain2

...

#  base config
location = /favicon.ico {
        log_not_found off;
        access_log off;
}

location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
}

location / {
        try_files $uri $uri/ /index.php;
}

location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
}

location ~ \.php$ {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

location ~* \.(png|jpg|jpeg|gif|ico)$ {
        expires 30d;
        access_log  off;
        log_not_found off;
}

location ~* \.(css|js)(\?ver=.*)?$ {
        expires 6h;
        log_not_found off;
}

...

Comments