学习aginx觉得挺费劲的,记录下所学习的的东西
server
{
#这是要监听的端口
listen 80;
#这是监听的服务器地址,也代表要访问的地址
server_name www.xlcode.top;
#网站的启动页
index index.php index.html index.htm default.php default.htm default.html;
#网站所在的位置,这里是webapss
root /www/server/tomcat/webapps/;
#代表访问:www.xlcode.top/
location /
{
#访问www.xlcode.top,就会被aginx代理到http://www.xlcode.top:8080,这就是代理
proxy_pass "http://www.xlcode.top:8080";
proxy_set_header Host www.xlcode.top;
proxy_set_header X-Forwarded-For $remote_addr;
}
# 代表访问:www.xlcode.top/public/
location /public/
{ #nginx会代理到http://www.xlcode.top:8081
proxy_pass "http://www.xlcode.top:8081";
}
# 所有的静态文件(gif,jpg)都会被映射到这个root根目录,所以当您访问另外一个文件夹下的静态资源时,会报404
location ~*.*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$
{
expires 12h;
}
#代表访问:www.xlcode.top/news
location /news
{ #nginx会代理到目录 /www/springboot/news;
root /www/springboot;
}
}
server
{
#这是要监听的端口8081
listen 8081;
server_name www.xlcode.top;
root /www/public/;
# 访问www.xlcode.top:8081会映射到 /www/public/目录下
location /
{
root /www/public;
}
# 访问www.xlcode.top:8081/public会映射到 /www/public/目录下,要仔细比较这二者的区别
location /public
{
root /www;
# index index.html;
}
}