在開發(fā)過程中,會(huì)需要在nginx中配置多個(gè)站點(diǎn)为迈,下面我們來舉例說明
有兩個(gè)站點(diǎn):
站點(diǎn)一:qamanage.magewise.cn 存放目錄為:D:\MIIC-MyWork\websit\QA_MANAGE_WEB
站點(diǎn)二:qa.magewise.cn 存放目錄為:D:\MIIC-MyWork\websit\QA_WEB
在Nginx配置目錄下三椿,創(chuàng)建一個(gè)”qa_web”目錄。本例假設(shè)Nginx是默認(rèn)安裝葫辐,配置目錄在”D:\nginx-1.15.9”
那么qa_web目錄就是:D:\nginx-1.15.9\qa_web
然后在該目錄下創(chuàng)建:qa_web.conf文件
內(nèi)容為:
server {
listen 80;
server_name qa.megawise.cn;
root D:\MIIC-MyWork\websit\QA_WEB;
charset utf-8;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /service/answer/ {
proxy_pass http://127.0.0.1:8081/answer/;
}
location /service/question/ {
proxy_pass http://127.0.0.1:8082/question/;
}
location /service/user/ {
proxy_pass http://127.0.0.1:8084/user/;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# 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;
#}
}
在qa_web目錄下創(chuàng)建qamanage_web.conf文件搜锰,其中內(nèi)容為:
server {
listen 80;
server_name qamanage.megawise.cn;
root D:\MIIC-MyWork\websit\QA_MANAGE_WEB;
charset utf-8;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /service/answer/ {
proxy_pass http://127.0.0.1:8081/answer/;
}
location /service/question/ {
proxy_pass http://127.0.0.1:8082/question/;
}
location /service/user/ {
proxy_pass http://127.0.0.1:8084/user/;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# 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;
#}
}
這兩個(gè)conf文件中只有
server_name 和 root配置不同
打開D:\nginx-1.15.9\conf目錄下的nginx.conf文件,將虛擬目錄的配置文件加入到”http {}”部分的末尾:
http {
...
include D:/nginx-1.15.9/qa_web/*.conf;
}
重啟Nginx服務(wù)
nginx -s reload
然后就可以訪問兩個(gè)站點(diǎn)了~~
最后耿战!一定要記椎暗稹:
將兩個(gè)站點(diǎn)的IP寫入host(C:\Windows\System32\drivers\etc)文件
127.0.0.1 qamanage.megawise.cn
127.0.0.1 qa.megawise.cn