运维笔记之centos7.9配置Nginx服务器

安装依赖包

yum -y install gcc pcre-devel zlib-devel openssl openssl-devel

下载Nginx包

http://nginx.org/en/download.html

安装Nginx

# 创建安装目录
mkdir -p /usr/soft/nginx
# 将下载文件拷贝到/usr/soft并解压
tar -zxvf nginx-1.24.0.tar.gz
# 编辑配置文件
cd nginx-1.24.0
./configure --prefix=/usr/soft/nginx
# 编译并安装
make install

启动nginx服务

cd /usr/soft/nginx/sbin/
# 启动Nginx服务
./nginx
# 查看服务状态
ps -ef | grep nginx
# 关闭Nginx服务
./nginx -s stop

配置nginx代理

修改 server.listen、server_name、location /、proxy_pass如下,完成由http://192.168.1.100:8081 跳转到 http://192.168.1.110:7879/SayHello
修改完配置文件后需要重启nginx服务

# 指定用户
user root;
# 指定线程数量
worker_processes  4;
# 配置Nginx反向代理
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    # 超时时间
    keepalive_timeout  65;
	# 是否压缩 
    #gzip  on;
	# 监听 http://192.168.1.100:8081 跳转到 http://192.168.1.110:7879/SayHello
    server {
        listen       8001;
        server_name  192.168.1.100;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://192.168.1.110:7879/SayHello;
        }

        #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;
        }
    }
}

你可能感兴趣的:(运维,笔记,nginx)