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

你可能感兴趣的文章
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.7 Parameters vs Hyperparameters
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>