1.安裝nginx
2.安裝好后進入Nginx目錄中
在conf目錄下建立一個vhost(ps:名字自己設定)文件夾
其中的$NGINXHOME為你的nginx目錄
#進入到nginx目錄 cd $NGINXHOME cd conf mkdir vhost
3.編輯nginx.conf加入如下一句話:
include vhost/*.conf;
然后保存
4.進入vhost文件夾中建立你需要的二級域名比如我需要建立tomcat.lonecloud.cn域名則建立tomcat.lonecloud.cn.conf
加入如下配置
server {
default_type 'text/html';
charset utf-8;
listen 80;
autoindex off;
server_name tomcat.lonecloud.cn;
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 / {
proxy_pass http://127.0.0.1:8080/;
add_header Access-Control-Allow-Origin *;
}
}
主要的配置是在:
listen為監聽端口為80端口
server_name設置為你需要的二級域名
location中的proxy_pass 設置為你的tomcat的路徑
5.重啟nginx即可
