nginx安装部署(实操)

nginx安装部署(实操)

下载安装包

安装

部署

一、准备安装包

wget http://nginx.org/download/nginx-1.10.2.tar.gz

wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz

wget http://zlib.net/zlib-1.2.11.tar.gz

wget https://netix.dl.sourceforge.net/project/pcre/pcre/8.40/pcre-8.40.tar.gz

在这里插入图片描述
安装C++编译环境

sudo yum install gcc-c++

在这里插入图片描述
二、安装NGINX及相关组件

OpenSSL安装:

tar -zxvf openssl-fips-2.0.10.tar.gz 

cd openssl-fips-2.0.10/

./config && make && make install

查看OpenSSL版本
pcre安装:

tar -zxvf pcre-8.40.tar.gz

cd pcre-8.40/

./configure && make && make install

zlib安装:

tar -zxvf zlib-1.2.11.tar.gz

cd zlib-1.2.11/

./configure && make && make install

NGINX安装:(安装nginx-1.10.2.tar.gz未安装成功,同样步骤安装nginx-1.20.2.tar.gz,成功!)

tar -zxvf nginx-1.20.2.tar.gz

cd nginx-1.20.2/

./configure  && make && make install

三、启动NGINX

查看安装位置:whereis nginx

[root@x86-103 nginx-1.20.2]# whereis nginx
nginx: /usr/local/nginx

进入带NGINX目录并启动

[root@x86-103 nginx]# cd /usr/local/nginx/
[root@x86-103 nginx]# ls
conf  html  logs  sbin
[root@x86-103 nginx]# /usr/local/nginx/sbin/nginx 
[root@x86-103 nginx]# 

查看NGINX进程

[root@x86-103 nginx]# ps -aux | grep nginx
root     2814713  0.0  0.0  32980   392 ?        Ss   14:38   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody   2814714  0.0  0.2  66588  4216 ?        S    14:38   0:00 nginx: worker process
root     2843725  0.0  0.0  12112  1112 pts/1    R+   14:39   0:00 grep --color=auto nginx
``
`

NGINX基本操作:
```bash
启动
[root@localhost ~]# /usr/local/nginx/sbin/nginx
停止/重启
[root@localhost ~]# /usr/local/nginx/sbin/nginx -s stop(quit、reload)
命令帮助
[root@localhost ~]# /usr/local/nginx/sbin/nginx -h
验证配置文件
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t
配置文件
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf

NGINX配置文件
进入nginx安装目录下的conf文件夹下

[root@x86-103 nginx]# cd conf/
[root@x86-103 conf]# ls
fastcgi.conf          fastcgi_params          koi-utf  mime.types          nginx.conf          scgi_params          uwsgi_params          win-utf
fastcgi.conf.default  fastcgi_params.default  koi-win  mime.types.default  nginx.conf.default  scgi_params.default  uwsgi_params.default
[root@x86-103 conf]# vim nginx.conf

设置web站点

#user  nobody;
worker_processes  1;
events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    # 设置web站点
    server {
        listen       8000;
    	server_name nginx.test1.com;

        location / {
            root   html;
            index  index.html index.htm;
        }
    }
}

保存并退出nginx

[root@x86-103 nginx]# sbin/nginx -s reload

开启外网访问

方法一:直接关闭防火墙,这样性能较好,但安全性较差,如果有前置防火墙可以采取这种方式

关闭防火墙
[root@localhost ~]# service iptables stop
关闭开机自启动防火墙
[root@localhost ~]# chkconfig iptables off
[root@localhost ~]# chkconfig --list|grep ipt

方法二:将开启的端口加入防火墙白名单中,这种方式较安全但性能也相对较差

编辑防火墙白名单
[root@localhost ~]# vim /etc/sysconfig/iptables
增加下面一行代码
-A INPUT -p tcp -m state -- state NEW -m tcp --dport 80 -j ACCEPT
保存退出,重启防火墙
[root@localhost ~]# service iptables restart

Linux配置完毕了,使用另一台电脑而非安装nginx的电脑,我是用的windows系统,配置一下host在“C:\Windows\System32\drivers\etc”下的hosts中配置一下域名重定向

10.11.13.22 nginx.test.com nginx.test1.com nginx.test2.com

然后cmd再ping一下这个域名是否正确指向了这个IP上

ping nginx.test1.com

正确指向后在telnet一下80端口看一下是否可以与端口通信(如果telnet提示没有此命令是没有安装客户端,在启用或禁用windows功能处安装后再操作即可)

telnet ip 8000

打开这台Windows系统内的浏览器,输入nginx.test.com,查看是否外网访问成功
nginx部署完成。

Nginx负载均衡配置可以参考以下文档,及相关nginx负载配置文档。
参考文档:
https://www.cnblogs.com/taiyonghai/p/6728707.html 参考文档

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值