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

你可能感兴趣的文章
npm install 卡着不动的解决方法
查看>>
npm install 报错 EEXIST File exists 的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 Failed to connect to github.com port 443 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>
npm install 报错 no such file or directory 的解决方法
查看>>
npm install 权限问题
查看>>
npm install报错,证书验证失败unable to get local issuer certificate
查看>>
npm install无法生成node_modules的解决方法
查看>>
npm install的--save和--save-dev使用说明
查看>>
npm node pm2相关问题
查看>>
npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
查看>>
npm run build报Cannot find module错误的解决方法
查看>>
npm run build部署到云服务器中的Nginx(图文配置)
查看>>
npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
查看>>
npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
查看>>
npm scripts 使用指南
查看>>
npm should be run outside of the node repl, in your normal shell
查看>>
npm start运行了什么
查看>>
npm WARN deprecated core-js@2.6.12 core-js@<3.3 is no longer maintained and not recommended for usa
查看>>