在nginx环境中配置多个站点
另一方面,一般在/etc/nginx/nginx.conf上找到nginx的配置文件
二.修改配置文件我的配置文件如下。 其中,服务器包含一个对象,一个站点对应一个服务器,多个服务器
#用户nobody;
工作器_ processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
事件{
worker_connections 10240;
multi_accept on;
use epoll;
}
http {
include mime.types;
efault _ type应用程序/octet-stream;
# log _ format main ' $ remote _ addr-$ remote _ user [ $ time _ local ] ' $ request ' '
# ' $ status $ body _ bytes _ sent ' $ http _ referer ' '
# ' ' $ http _ user _ agent ' ' $ http _ x _ forwarded _ for ';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
//第一个站点配置是查看关键点(域名定位到的项目地址) ) )。
服务器{
listen 80
server_name localhost; //你的域名很重要
#charset koi8-r;
# access _ loglogs/host.access.log main;
index index.PHP index.htmlindex.htm;
if (! -e $request_filename ) {
rewrite^(.*$/index.PHP? s=$1 last;
布雷克;
}
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi _ param script _ filename/scripts $ fastcgi _ script _ name;
包括fastcgi _ params;
set $path_info ';
set $ real _ script _ name $ fastcgi _ script _ name;
if ) $fastcgi_script_name^ (? .PHP((/. ) $ ' ) ) )。
set $real_script_name $1;
set $path_info $2;
}
fastcgi _ param script _ filename $ document _ root $ real _ script _ name;
fastcgi _ param script _ name $ real _ script _ name;
fastcgi _ param path _ info $ path _ info;
}
#error_page 404 /404.html;
# redirectservererrorpagestothestaticpage/50x.html
#
error _ page 500502503504/50x.html;
}
# proxythephpscriptstoapachelisteningon 127.0.0.1:80
proxy_pass http://127.0.0.1;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
}
//第二个站点配置如第一配置一样只是需要改变域名和定位到的项目地址
server {
listen 80;
server_name ruigao.cqgoulian.com;
#charset koi8-r;
#access_log logs/host.access.log main;
index index.php index.html index.htm;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
proxy_pass http://127.0.0.1;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
}
三、重启nginx 输入命令行 # service nginx restart 提示OK则代表成功 提示警告内容则需要修改问题
四、打开游览器访问不同站点的域名 发现定位到不同的项目地址 成功!
转载至链接:https://my.oschina.net/u/3587107/blog/1920644