配置host
C:\Windows\System32\drivers\etc\hosts
用nginx等做代理转发到本机时最好通过host配置目的地址为127.0.0.1
配置conf
在主配置文件nginx.conf下引入其他conf
http {
... ...
include vhost/*.conf;
... ...
}
1 在vhost/image.imooc.com.conf文件里,进行文件服务器配置,转发到目录上
server {
listen 80;
autoindex off;
server_name image.imooc.com;
access_log e:/access.log combined;
index index.html index.htm index.jsp index.php;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location ~ /(mmall_fe|mmall_admin_fe)/dist/view/* {
deny all;
}
location / {
root E:\ftpfile\img;
add_header Access-Control-Allow-Origin *;
}
}
参数解释
autoindex:是否自动创建索引,若设置off,直接输入域名则会报403错误,但是仍能通过URL访问里面的资源。
2 配置tomcat服务器的反向代理,转发到HTTP的IP地址和端口上
server {
listen 80;
autoindex on;
server_name tomcat.imooc.com;
access_log e:/access.log combined;
index index.html index.htm index.jsp index.php;
#error_page 404 /404.html;
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 404;
}
location / {
proxy_pass http://127.0.0.1:8080;
add_header Access-Control-Allow-Origin *;
}
}
nginx命令
测试配置文件
nginx.exe -t
reload配置文件
nginx.exe -s reload
启动nginx
nginx.exe