关于java:linux系统安装nginx

7次阅读

共计 1554 个字符,预计需要花费 4 分钟才能阅读完成。

1. 下载 nginx

1.1 官网下载

官网:http://nginx.org/en/download….
windows 零碎下关上官网下载一个 linux 零碎的 nginx, 之后再传到 linux 零碎中, 这样比间接在 yum 中下载的版本更新些;

1.2 上传安装包

上传到指定目录中 /usr/local/src/

1.3 解压 nginx 压缩包

命令:tar -xvf 包名

1.3.1 解决压缩包

把压缩包挪动到指定目录下或删除,software 目录是为了对立治理压缩包而创立的目录

1.3.2 批改文件名

1.4 装置 nginx 服务器

1)在 nginx-source 的根目录中执行命令: ./configure

实现

2) 在 nginx-source 的根目录中执行命令: make
[root@localhost nginx-source]# make

3)在 nginx-source 的根目录中执行命令: make install
[root@localhost nginx-source]# make install

1.5 跳转到 nginx 的工作目录

1.5.1 查找 nginx 工作目录

命令:whereis nginx

1.5.2 跳转

1.6 启动 nginx

1)进入 nginx/sbin 目录中
2) 在 sbin 目录下执行启动命令
启动命令: ./nginx
重启命令: ./nginx -s reload
敞开命令: ./nginx -s stop

1.7 批改 nginx 配置文件

1.7.1 需要:

1)实现图片反向代理
2) 实现 tomcat 负载平衡实现

1.7.2. 关上配置文件

地位:/usr/local/nginx/conf/nginx.conf

关上 nginx.conf 文件

批改配置文件

`server {
    #配置图片代理服务器  http://image.jt.com:80
    listen 80;
    server_name image.jt.com;
    location / {
        #root  D:/JT-SOFT/images;
        root  /usr/local/src/images;
    }    
}

#配置商品后盾服务器
server{
    listen  80;
    server_name manage.jt.com;

    location / {
        #代理实在服务器地址
        #proxy_pass http://localhost:8091;
        #映射到集群
        #proxy_pass  http://jtWindows;
        proxy_pass  http://jtLinux;
    }
}

#配置 tomcat 服务器集群  1. 默认 轮询策略  2. 权重策略  3.ip_hash 策略
upstream jtWindows {
    #ip_hash;     down 标识宕机     backup 备用机
    #max_fails=1          示意最大的失败次数
    #fail_timeout=60s    如果拜访不通, 则在 60 秒内, 不会再次拜访故障机
    server 127.0.0.1:8081 max_fails=1 fail_timeout=60s;
    server 127.0.0.1:8082 max_fails=1 fail_timeout=60s;
    server 127.0.0.1:8083 max_fails=1 fail_timeout=60s;
}

upstream jtLinux {
    server 192.168.126.129:8081;
    server 192.168.126.129:8082;
    server 192.168.126.129:8083;
}

`

1.7.3 批改实现后重启 nginx

重启命令: ./nginx -s reload

1.8 批改 hosts 文件

1.8.1hosts 文件阐明

应用域名拜访服务器须要把域名进行解析,hosts 能够对本机的域名进行解析, 能满足测试的需要, 但商品一上线就须要花钱注册域名了,hosts 就不能够了;

1.8.2 批改 hosts

批改的时候须要用到超级管理员的权限, 关上的形式用以管理员形式关上;

正文完
 0