Nginx技术问答:http://linux.xyz/topic/Nginx

1.基于域名的虚拟主机

使用域名www.linux.xyz为例!

server {
    listen  80;
    server_name www.linux.xyz;
    error_page  404  /404.html;

    location / {
        root html/www;
        index index.html;
        access_log logs/www.linux.xyz_access.log main;
        error_log logs/www.linux.xyz_error.log;
    }
    
    location ~ .+\.php.*$ {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME  $request_filename;
        include  fastcgi_params;
    }

}

2.基于端口的虚拟主机

以端口8080为例,域名依然使用www.linux.xyz

server {
    listen  8080;
    server_name www.linux.xyz;
    error_page  404  /404.html;

    location / {
        root html/port;
        index index.html;
        access_log logs/www.linux.xyz_access.log main;
        error_log logs/www.linux.xyz_error.log;
    }

    location ~ .+\.php.*$ {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME  $request_filename;
        include  fastcgi_params;
    }

}

基于IP的虚拟主机

以192.168.1.88为默认Ip配置虚拟主机

server {
    listen  80;
    server_name 192.168.1.88;
    error_page  404  /404.html;

    location / {
        root html/ipvhosts;
        index index.html;
        access_log logs/192.168.1.88_access.log mian;
        error_log logs/192.168.1.88_error.log;
    }
    
    location ~ .+\.php.*$ {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME  $request_filename;
        include  fastcgi_params;
    }

}