ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
配置基于名称的虚拟主机,我们需要提前做好DNS记录,并且要求每个虚拟主机独立放一个文件,然后在nginx.conf中include包含进来 案例: 域名: bbs.51pet.com www.51pet.com 服务器IP: 10.2.11.245 网站目录: /application/bbs /application/www 日志文件: /applicaiton/bbs/logs /application/www/logs 配置文件: /etc/nginx/conf.d/bbs.conf /etc/nginx/conf.d/www.conf [root@static ~]# mkdir -p /application/{bbs,www}/logs [root@static nginx]# mkdir conf.d [root@static nginx]# cd conf.d/ 配置虚拟主机一:bbs.51pet.com [root@static conf.d]# vim bbs.conf server { listen 80; server_name bbs.51pet.com; #charset koi8-r; access_log /application/bbs/logs/bbs.access.log main; location / { root /application/bbs/; index index.php index.html index.htm; #if (!-e $request_filename) { # rewrite ^/(.*)$ /index.php/$1 last; #} } #error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php/?.*$ { root /application/www; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; } } 配置虚拟主机二: server { listen 80; server_name www.51pet.com; #charset koi8-r; access_log /application/www/logs/www.access.log main; location / { root /application/bbs/; index index.php index.html index.htm; #if (!-e $request_filename) { # rewrite ^/(.*)$ /index.php/$1 last; #} } #error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php/?.*$ { root /application/bbs; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; } } 然后在nginx.conf包含进这两个虚拟主机文件 include conf.d/*.conf; (配置在http段) [root@static conf.d]# /usr/local/nginx/sbin/nginx -s reload 最后测试: [root@static conf.d]# echo bbs.51pet.com > /application/bbs/index.html [root@static conf.d]# echo www.51pet.com > /application/www/index.html