1. 本地开发好的demo程序,target目录下,把META-INF 、WEB-INF、index.jsp 所有文件打成zip包,如下图:

2. Linux服务器下,部署到Tomcat下,清空ROOT目录下所有文件,把1中nginx.zip文件放到ROOT目录下,解压后,切换到
Tomcat bin目录下,启动Tomcat即可。关闭防火墙,外面就能通过 端口:IP进行访问。
-
# 解压 -
[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安装配置
安装目录:/usr/local/nginx
4. 配置nginx进行域名访问
-
[root@localhost conf]# pwd -
/usr/local/nginx/conf -
[root@localhost conf]# cat -n nginx.conf


5. 附上主要配置代码配置
#gzip on;upstream testnginx{server localhost:8080;#server localhost:8081;}server {listen 80;server_name www.testnginx.com;#charset koi8-r;#access_log logs/host.access.log main;location / {proxy_pass http://testnginx;#proxy_pass http://localhost:8080;#proxy_set_header Host $http_host;#proxy_set_header X-Real-IP $remote_addr;#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;#index index.html index.htm;}#error_page 404 /404.html;
6. 修改了配置,重新加载nginx
-
[root@localhost sbin]# pwd -
/usr/local/nginx/sbin -
[root@localhost sbin]# ./nginx -s reload
没有sbin的直接nginx 回车启动
7. 因为没有统一的DNS设置(一般公司有,可以做统一解析),所以需要修改本地的host文件如下,做域名 ip的映射。因为外网的DNS解析不了上面nginx自己配置的域名 www.testnginx.com,所以请求不到的。host配置如下:
-
host路径: C:\Windows\System32\drivers\etc -
文件内容: 192.168.85.128 www.testnginx.com


8. 访问结果如下:


















