博客
关于我
搭建http网页——Nginx+Tomcat版
阅读量:531 次
发布时间:2019-03-08

本文共 2416 字,大约阅读时间需要 8 分钟。

搭建http网页——Nginx+Tomcat版

实验环境:CentOS 7,防火墙已关闭

实验目的是部署Nginx反向代理,使用域名访问Tomcat的8080服务(不需要端口可直接访问)

已搭建好Tomcat服务,浏览器可通过端口访问界面


安装Nginx

安装前可通过whereis nginx查看是否已安装Nginx

安装前准备:c++语言环境(已安装)、openssl、pcre、zlib组件(已成功安装)

[root@qmfz]# yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel已加载插件:fastestmirrorLoading mirror speeds from cached hostfile* base: mirrors.njupt.edu.cn* extras: mirrors.ustc.edu.cn* updates: mirrors.ustc.edu.cn软件包 gcc-4.8.5-44.el7.x86_64 已安装并且是最新版本软件包 zlib-1.2.7-18.el7.x86_64 已安装并且是最新版本...(剩余安装过程类似)

手动安装Nginx

Nginx默认安装在/usr/local目录下

  • 创建Nginx目录并进入
  • [root@qmfz]# mkdir nginx && cd nginx

    2.下载Nginx压缩包

    [root@qmfz]# wget http://nginx.org/download/nginx-1.14.2.tar.gz

    3.解压安装包

    [root@qmfz]# tar -zxvf nginx-1.14.2.tar.gz

    4.进入目录并进行配置

    [root@qmfz]# cd nginx-1.14.2[root@qmfz]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx \--conf-path=/usr/local/nginx/conf/nginx.conf \--with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_v2_module

    5.编译安装

    [root@qmfz]# make && make install

    6.配置环境变量

    [root@qmfz]# echo "export NGINX_HOME=/usr/local/nginx" >> /etc/profile[root@qmfz]# source /etc/profile

    7.设置为系统服务并启动

    [root@qmfz]# vi /lib/systemd/system/nginx.service
    [Unit]Description=nginx serviceAfter=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s quitPrivateTmp=true[Install]WantedBy=multi-user.target

    8.启动并重启服务

    [root@qmfz]# systemctl enable nginx[root@qmfz]# systemctl start nginx[root@qmfz]# systemctl restart nginx

    配置Nginx反向代理

    1.进入Nginx配置目录

    [root@qmfz]# cd /usr/local/nginx/conf/

    2.创建vhost目录并新建配置文件

    [root@qmfz]# mkdir -p vhost[root@qmfz]# cd vhost[root@qmfz]# vim chenshuyi.biuayi.cn.conf

    Nginx配置文件示例

    server {    listen 80;    autoindex on;    server_name chenshuyi.biuayi.cn; # 使用的域名    access_log /usr/local/nginx/logs/access.log combined;    index index.html index.htm index.jsp index.php;    # 防止目录Traversal攻击    if ($query_string ~* ".*[\;'\<\>].*") {        return 404;    }    location / {        proxy_pass http://127.0.0.1:8080; # Tomcat服务地址                # 允许跨域访问        add_header Access-Control-Allow-Origin "*";    }}

    3.在Nginx配置文件中添加以下内容(通常在http节点下)

    include vhost/*\.conf;

    4.重启Nginx服务并确保Tomcat运行正常

    [root@qmfz]# cd /usr/local/nginx/sbin/[root@qmfz]# ./nginx -s reload

    测试访问

    通过浏览器访问域名https://chenshuyi.biuayi.cn即可查看配置效果

    转载地址:http://gikiz.baihongyu.com/

    你可能感兴趣的文章
    MySQL5.7.18主从复制搭建(一主一从)
    查看>>
    MySQL5.7.19-win64安装启动
    查看>>
    mysql5.7.19安装图解_mysql5.7.19 winx64解压缩版安装配置教程
    查看>>
    MySQL5.7.37windows解压版的安装使用
    查看>>
    mysql5.7免费下载地址
    查看>>
    mysql5.7命令总结
    查看>>
    mysql5.7安装
    查看>>
    mysql5.7性能调优my.ini
    查看>>
    MySQL5.7新增Performance Schema表
    查看>>
    Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
    查看>>
    Webpack 之 basic chunk graph
    查看>>
    Mysql5.7版本单机版my.cnf配置文件
    查看>>
    mysql5.7的安装和Navicat的安装
    查看>>
    mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
    查看>>
    Mysql8 数据库安装及主从配置 | Spring Cloud 2
    查看>>
    mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
    查看>>
    MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
    查看>>
    MYSQL8.0以上忘记root密码
    查看>>
    Mysql8.0以上重置初始密码的方法
    查看>>
    mysql8.0新特性-自增变量的持久化
    查看>>