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

你可能感兴趣的文章
ThreadLocal线程内部存储类
查看>>
thinkphp 常用SQL执行语句总结
查看>>
Oracle:ORA-00911: 无效字符
查看>>
Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
查看>>
TCP基本入门-简单认识一下什么是TCP
查看>>
tableviewcell 中使用autolayout自适应高度
查看>>
Symbolic Aggregate approXimation(SAX,符号聚合近似)介绍-ChatGPT4o作答
查看>>
Orcale表被锁
查看>>
svn访问报错500
查看>>
Orderer节点启动报错解决方案:Not bootstrapping because of 3 existing channels
查看>>
org.apache.ibatis.exceptions.PersistenceException:
查看>>
org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
查看>>
org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
查看>>
org.apache.poi.hssf.util.Region
查看>>
org.apache.xmlbeans.XmlOptions.setEntityExpansionLimit(I)Lorg/apache/xmlbeans/XmlOptions;
查看>>
org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
查看>>
org.hibernate.HibernateException: Unable to get the default Bean Validation factory
查看>>
org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
查看>>
SQL-CLR 类型映射 (LINQ to SQL)
查看>>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
查看>>