1. 本地开发好的demo程序,target目录下,把META-INF 、WEB-INF、index.jsp 全部文件打成zip包,以下图:html
2. Linux服务器下,部署到Tomcat下,清空ROOT目录下全部文件,把1中nginx.zip文件放到ROOT目录下,解压后,切换到nginx
Tomcat bin目录下,启动Tomcat便可。关闭防火墙,外面就能经过 端口:IP进行访问。web
# 解压 [root@localhost ROOT]# unzip nginx.zip [root@localhost ROOT]# /opt/apache-tomcat-8.5.34/webapps/ROOT [root@localhost ROOT]# ls index.jsp META-INF nginx.zip WEB-INF # bin下 启动Tomcat [root@localhost bin]# ./startup.sh
3. 安装nginx,参考 nginx安装配置apache
安装目录:/usr/local/nginxtomcat
4. 配置nginx进行域名访问服务器
[root@localhost conf]# pwd /usr/local/nginx/conf [root@localhost conf]# cat -n nginx.conf
5. 附上主要配置代码配置app
#gzip on; 34 35 upstream testnginx{ 36 server localhost:8080; 37 #server localhost:8081; 38 } 39 server { 40 listen 80; 41 server_name www.testnginx.com; 42 43 #charset koi8-r; 44 45 #access_log logs/host.access.log main; 46 47 location / { 48 proxy_pass http://testnginx; 49 #proxy_pass http://localhost:8080; 50 #proxy_set_header Host $http_host; 51 #proxy_set_header X-Real-IP $remote_addr; 52 #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 53 #index index.html index.htm; 54 } 55 56 #error_page 404 /404.html;
6. 修改了配置,从新加载nginxwebapp
[root@localhost sbin]# pwd /usr/local/nginx/sbin [root@localhost sbin]# ./nginx -s reload
7. 由于没有统一的DNS设置(通常公司有,能够作统一解析),因此须要修改本地的host文件以下,作域名 ip的映射。由于外网的DNS解析不了上面nginx本身配置的域名 www.testnginx.com,因此请求不到的。host配置以下:jsp
host路径: C:\Windows\System32\drivers\etc 文件内容: 192.168.85.128 www.testnginx.com
8. 访问结果以下:.net