当前位置:   首页安装配置安装资源库:Linux环境下安装Nginx及其使用

安装资源库:Linux环境下安装Nginx及其使用

发布日期:2021-12-24 16:33 | 文章来源:脚本之家

一、查看CentOS的版本

cat /etc/redhat-release

二、添加资源库

在 CentOS 系统上安装 Nginx ,得先去添加一个资源库:

vim /etc/yum.repos.d/nginx.repo
  [nginx]
  name=nginx repo
  baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  gpgcheck=0
  enabled=1

三、安装nginx

yum -y install nginx


四、测试nginx配置文件是否正确

nginx -t

打印如下:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

五、CentOS7.0+ nginx实现停止、启动、重启

systemctl stop nginx.service  
systemctl start nginx.service
systemctl restart nginx.service
systemctl status nginx.service

开机自启:

systemctl enable nginx.service

取消开机自启:

systemctl disable nginx.service

六、nginx.conf配置示例

我的配置:

user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid    /var/run/nginx.pid;

events {
  worker_connections 1024;
}

http {
  include    /etc/nginx/mime.types;
  default_type application/octet-stream;
  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_age

常用的nginx.conf配置:

user www www;
worker_processes 2;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid    logs/nginx.pid;
events {
  use epoll;
  worker_connections 2048;
}
http {
  include    mime.types;
  default_type application/octet-stream;
  #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  #         '$status $body_bytes_sent "$http_referer" '
  #         '"$http_user_age

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持本站。

联系我们
关于使用场景和技术架构的更多咨询,请联系我们的销售和技术支持团队。
Yingsoo Host

在线
客服

在线客服:7*24小时在线

客服
热线

400-630-3752
7*24小时客服服务热线

关注
微信

关注官方微信
顶部