1、进入nginx目录cd conf:创建文件夹
sudo mkdir vhost,cd vhost,sudo vim www.fanxing.store.conf,添加如下内容
server {
default_type ‘text/html‘;
charset utf-8;
listen 80;
autoindex on;
server_name www.fanxing.store;
access_log /usr/local/nginx/logs/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 /product/ftpfile/learning/;
proxy_pass http://127.0.0.1:8080; //暂时跳到tomcat
add_header Access-Control-Allow-Origin *;
}
}
保存
2.重启nginx:sudo ../../sbin/nginx -s rload
3.配置文件服务器
server {
listen 80;
autoindex off;
server_name image.fanxing.store;
access_log /usr/local/nginx/logs/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 /ftpfile/;
add_header Access-Control-Allow-Origin *;
}
}
*****出现404Not Found:image.fanxing.store末尾未加.conf,如果未配置,默认加载nginx/下的nginx.conf
(nginx: [warn] conflicting server name "image.fanxing.store" on 0.0.0.0:80, ignored,)
nginx -s reload
重启nginx报错。
[warn]: conflicting server name “domain.com” on 0.0.0.0:80, ignored
检查:server/nginx-1.4.7/conf/vhosts 下的配置文件,应该有重复绑定域名的,找到,修改或删除即可。
如果image.fanxing.store.conf:autoindex off;就无法访问目录结构,出现403forbidden错误,不可访问;
*******