linux-nginx

首先我们跳转到nginx安装的地方

cd usr/local

下载nginx: 测试使用1.16.1

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

其他版参照官网地址:http://nginx.org/en/download.html
在这里插入图片描述

  1. 解压到当前目录下:
tar -zxvf  nginx-1.16.1.tar.gz
  1. 执行命令:

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

如果以上三个步骤出现了问题,基本是一些插件编辑器没有安装,安装如下:

安装插件:在根目录安装即可

  1. 查看gcc是否安装

    gcc是语言编辑器,当下可以编辑基本所有的高级语言如java/pascal/go等以及C、C++

gcc -v

安装方法:

yum -y install gcc

在这里插入图片描述

  1. 安装pcre
    解决正则以及函数的使用
yum install -y pcre pcre-devel

在这里插入图片描述

  1. 安装zlib:
    提供各种的压缩方式
yum install -y zlib zlib-devel
  1. 安装openssl
    开源的安全通信包
yum install -y openssl openssl-devel

!最后回到下载nginx里面的步骤三个命令即可完成nginx的安装成功

修改nginx端口号等配置

  1. 此时在usr/local里面会产生一个nginx文件夹
cd usr/local/nginx/conf

在这里插入图片描述

  1. 打开nginx.conf文件编辑下
vi nginx.conf

在这里插入图片描述

  1. 配置如下
user admin;  #用户名
worker_processes  1;  #工作进程:数目。根据硬件调整,通常等于cpu数量或者2倍cpu数量。
pid         /usr/local/nginx/logs/nginx.pid;  # nginx进程pid存放路径

events {
    worker_connections  1024; # 工作进程的最大连接数量
}
##test

http {
    include       mime.types; #指定mime类型,由mime.type来定义
    default_type  application/octet-stream;
    sendfile        on; #指定nginx是否调用sendfile函数来输出文件,对于普通应用,必须设置on。
    keepalive_timeout  65;
    
	## 虚拟主机
    server {
        listen       80;  #开启端口
        server_name physical.tdr.tech;  #端口号域名代替ip地址(192.168.0.2) 域名可以有多个,用空格隔开

       #压缩转发:基本默认为以下内容
        gzip  on;
        gzip_vary on;
        gzip_min_length 100k;
        gzip_buffers 128 128k;
        gzip_comp_level 6;
        gzip_types  text/plain application/javascript application/x-javascript application/json text/css text/scss application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-icon;
        client_max_body_size 200M;
        proxy_connect_timeout 10;
        proxy_send_timeout 30;
        proxy_read_timeout 60;
        #压缩转发
        
        #默认ip地址启动的地址,比如ip地址:192.168.0.2,启动后会看到index.html内容
        location / {
            root   html;
            index  index.html index.htm;
        }

        # 项目启动地址:192.168.0.2/ftdp_mobile_prod
        location /ftdp_mobile_prod {
            root /home/admin/physical-ftdp;
            index index.html;
        }
		#local/html/50.html文件
        location = /50x.html {
            root   html;
        }
    }
}

启动nginx:

  1. 进入usr/local/nginx/sbin
cd usr/local/nginx.sbin

在这里插入图片描述

  1. 启动nginx
./nginx
  1. 重启nginx
./nginx -s reload


# 判断是配置文件是否正常:
./nginx -t
  1. 关闭nginx
#查询nginx主进程号
ps -ef|grep nginx

#正常停止: 
kill -QUIT 主进程号

#快速停止
kill -TERM 主进程号

#强制停止
kill -9 nginx

#如果nginx.com配置了pid文件路径,如果没有则在logs目录下
kill -信号类型'usr/local/nginx/logs/nginx.pid'

访问ip地址:192.168.0.2 即可访问到
可以将这个服务器所有地址放到usr/local/html/index.html中,在里面配置超链接即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章