博客
关于我
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/

你可能感兴趣的文章
Qt笔记——模型/视图MVD 文件目录浏览器软件
查看>>
POJ 2892 Tunnel Warfare(树状数组+二分)
查看>>
poj 2965 The Pilots Brothers' refrigerator-1
查看>>
poj 3026( Borg Maze BFS + Prim)
查看>>
POJ 3041 - 最大二分匹配
查看>>
POJ 3041 Asteroids(二分匹配模板题)
查看>>
Qt笔记——标准文件对话框QFileDialog
查看>>
poj 3083 Children of the Candy Corn
查看>>
POJ 3083 Children of the Candy Corn 解题报告
查看>>
POJ 3253 Fence Repair C++ STL multiset 可解 (同51nod 1117 聪明的木匠)
查看>>
Qt笔记——控件总结
查看>>
poj 3262 Protecting the Flowers 贪心
查看>>
poj 3264(简单线段树)
查看>>
Qt笔记——布局管理三件套分割窗口、停靠窗口和堆栈窗口
查看>>
poj 3277 线段树
查看>>
POJ 3349 Snowflake Snow Snowflakes
查看>>
POJ 3411 DFS
查看>>
poj 3422 Kaka's Matrix Travels (费用流 + 拆点)
查看>>
Qt笔记——官方文档全局定义(二)Functions函数
查看>>
POJ 3468 A Simple Problem with Integers
查看>>