博客
关于我
Linux安装Nginx
阅读量:545 次
发布时间:2019-03-09

本文共 885 字,大约阅读时间需要 2 分钟。

CentOS上安装Nginx并优化配置指南

一、安装依赖软件

首先,确保服务器已安装以下必要软件包:

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

二、下载与编译安装Nginx

下载最新版本的Nginx源码包并开始安装:

wget http://nginx.org/download/nginx-1.14.2.tar.gztar zxvf nginx-1.14.2.tar.gz

进入解压后的目录,执行编译命令:

cd nginx-1.14.2make make install

注意: 请根据需要选择是否安装Nginx作为服务。如果需要运行为后台程序,可以在编译时添加参数 --withดาًء.

三、配置Nginx服务器

默认配置文件位于 /usr/local/nginx/conf/nginx.conf。建议先复制模板并进行修改:

vim /usr/local/nginx/conf/nginx.conf

修改 server 块中的 listen 端口号为所需端口:

listen 8085;

四、启动Nginx服务

开始Nginx服务并使其随系统启动:

cd /usr/local/nginx/sbin/./nginx# 或使用启动脚本:  ./nginx -c /usr/local/nginx/conf/nginx.conf

检查启动状态:

curl localhost:8085

五、防火墙设置

为了让服务能够被外部访问,在CentOS 7+系统中关闭防火墙或设置相应防火墙规则:

systemctl stop firewalld.service

六、管理Nginx

常用命令:

  • 启动服务:

    ./nginx
  • 关闭服务:

    ./nginx -s stop
  • 重新加载配置:

    ./nginx -s reload
  • 停止并重新启动服务:

    ./nginx -s stop; ./nginx -s start

七、文档与资源

更多Nginx学习资源,可参考其官方文档或相关技术博客。

转载地址:http://bgmsz.baihongyu.com/

你可能感兴趣的文章
notepad++正则表达式替换字符串详解
查看>>
notepad如何自动对齐_notepad++怎么自动排版
查看>>
Notes on Paul Irish's "Things I learned from the jQuery source" casts
查看>>
Notification 使用详解(很全
查看>>
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
查看>>
NotImplementedError: Could not run torchvision::nms
查看>>
nova基于ubs机制扩展scheduler-filter
查看>>
Now trying to drop the old temporary tablespace, the session hangs.
查看>>
nowcoder—Beauty of Trees
查看>>
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>
np.power的使用
查看>>
NPM 2FA双重认证的设置方法
查看>>
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>
npm ERR! ERESOLVE could not resolve报错
查看>>
npm ERR! fatal: unable to connect to github.com:
查看>>
npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
查看>>
npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
查看>>
npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
查看>>
npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
查看>>