Centos7安装nginx

一丶安装

1.yum 安装(自带环境变量)

# 1.Centos7中添加nginx源
>>> rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# yum 安装
>>> yum install nginx -y

2.源码安装

# 1.安装nginx依赖包
>>> yum -y install gcc gcc-c++ zlib zlib-devel pcre-devel openssl openssl-devel make libtool 
# 2.创建nginx目录
>>> cd /etc
>>> mkdir nginx
>>> cd nginx
# 3.下载nginx安装包:http://nginx.org/en/download.html
>>> wget http://nginx.org/download/nginx-1.13.7.tar.gz
>>> tar -xvf nginx-1.13.7.tar.g
# 4.安装nginx
>>> cd /etc/nginx
>>> ./configure
>>> make && make install

二丶配置nginx

# 1. 添加ngnx配置文件(yum安装)
>>> cd /etc/nginx/conf.d/
>>> touch  xxx.conf
>>> vim xxx.conf
server {
    listen	 PORT;
    server_name  IP;
    
    gzip on;
    
    charset utf-8;
    
    gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;
    
    # nginx启动日志 
    access_log  /var/log/nginx/manage_callin_access.log  main;
    error_log   /var/log/nginx/manage_callin_error.log;

    error_page   401 402 403 404 /404.html;
    location = /404.html {
        root /home//www;
    }
    error_page   500 501 502 503 /500.html;
    location = /500.html {
        root /home//www;
    }
    # 静态文件转发
    location  ~^/(images|image|file)/ {
        # 以images、image、file开头
	# ip:port/images/myfile.txt  会去找 home/static/images/myfile.txt
        root /home/static/;
    }    	
    location = / {
                #proxy_pass DOMAIN/IP:PORT;
                root /home//www/;
                index index.html index.htm;
    }    
    location / {
                uwsgi_buffer_size 64k;
                uwsgi_buffers   32 32k;
                uwsgi_busy_buffers_size 128k;

                # 断点续传
                add_header Accept-Ranges bytes; 
                include uwsgi_params;

                # 指定uwsgi的sock文件所有动态请求就会直接丢给他
                uwsgi_pass  unix:/home//web/uwsgi.sock;

    }
    
}

# 2. 修改配置文件(源码安装)
>>> vim /etc/nginx/conf/nginx.conf

三丶nginx常用命令

# 启动
/usr/sbin/nginx
# 关闭
/usr/sbin/nginx -s stop
# 重启
/usr/sbin/nginx -s reload
# 开机自启
systemctl start nginx.service
systemctl enable nginx.service

四丶卸载nginx

1.yum安装卸载

yum remove nginx

2.源码安装卸载

# 1.查看nginx安装目录
>>> whereis nginx
nginx: /usr/sbin/nginx
# 2.删除nginx自启动
>>> chkconfig nginx off
# 3.停止nginx服务
>>> /usr/sbin/nginx -s stop
# 4.删除nginx安装目录
>>> rm -rf /etc/nginx
# 5.检查是否有残余
>>> find / -name nginx
/usr/libexec/initscripts/legacy-actions/nginx
>>> rm -rf /usr/libexec/initscripts/legacy-actions/
posted @ 2019-10-17 17:05  丶小白吖  阅读(492)  评论(0编辑  收藏  举报