操作系統(tǒng):mint17.2
1.進(jìn)入cd /opt/nginx/conf
2.sudo mkdir vhost
3.修改nginx配置文件,sudo gedit nginx.conf
include vhost/*.conf;//添加這條語(yǔ)句
# HTTPS server?
4.因?yàn)槭莾?nèi)網(wǎng)模擬,編輯/etc/hosts,配置
192.168.3.9? www.fruit.com
192.168.3.9 image.fruit.com
192.168.3.9? s.fruit.com
5.進(jìn)入vhost里面
cd /opt/nginx/conf/vhost
6.在vhost里面創(chuàng)建文件
sudo gedit www.fruit.com.conf
里面的內(nèi)容如下:
server {
listen 80;
autoindex on;
server_name www.fruit.com;
access_log /opt/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 / {
proxy_pass http://127.0.0.1:8080;
add_header Access-Control-Allow-Origin *;
}
}
7.重啟nginx
用nginx -c指定配置文件位置
sudo /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
sudo /opt/nginx/sbin/nginx -s reload 重啟nginx
訪問(wèn):www.fruit.com則訪問(wèn)到tomcat(域名轉(zhuǎn)發(fā)的一種)
8.在vhost里面創(chuàng)建文件image.fruit.com.conf
server {
listen 80;
autoindex off;
server_name image.fruit.com;
access_log /opt/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 *;
}
}
重啟nginx(域名映射到文件夾)
sudo /opt/nginx/sbin/nginx -s reload
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT防火墻打開80端口