CentOS 7安装nginx
程序员文章站
2024-02-21 09:45:10
...
1 配置yum本地nginx仓库
执行命令vim /etc/yum.repos.d/nginx.repo
编辑ngnix.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
说明:
name= #一个描述,随意。
baseurl= #设置资源库的地址
gpkcheck=0 表示对从这个源下载的rpm包不进行校验 , 1是校验;
enable=1 表示启用这个源 , 0是禁用。
2 启用配置
若启用主线:
yum-config-manager --enable nginx-mainline
若启用稳定版:
yum-config-manager --enable nginx-stable
3 执行安装
yum install ngnix
4 查看安装位置&版本
安装位置
whereis nginx
版本
nginx -v
5 nginx配置文件
配置文件:/etc/nginx/nginx.conf
默认配置文件:/etc/nginx/default.conf
vim /etc/nginx/nginx.conf
nginx.conf
user nginx; #设置用户
worker_processes 4; #工作进程数,一般设置为cpu核心数
error_log /var/log/nginx/error.log warn; #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
pid /var/run/nginx.pid; #指定nginx进程运行文件存放地址
daemon on; #配置是否后台启动,如需取消,则不配置
events {
worker_connections 1024; ##最大连接数,默认为512
}
http {
include /etc/nginx/mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型,默认为text/plain
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; #自定义格式
access_log /var/log/nginx/access.log main; #combined为日志格式的默认值
sendfile on; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。
#tcp_nopush on;
keepalive_timeout 65; #连接超时时间,默认为75s,可以在http,server,location块。
#gzip on;
include /etc/nginx/conf.d/*.conf;
server {
listen 800; #监听端口
server_name localhost; #监听地址
location / { #首页
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html; #错误页
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
6 启动等nginx命令
启动nginx
systemctl start nginx
停止nginx
systemctl stop nginx
查看nginx启动状态
systemctl status nginx
参考文献
https://blog.csdn.net/MacWx/article/details/98174136
https://blog.csdn.net/qq_41709494/article/details/99455441
上一篇: js之Generator函数(ES6)
下一篇: 一次关于tcpdump的使用心得
推荐阅读
-
CentOS 7安装nginx
-
CentOS安装部署MariaDB
-
CentOS 7下MySQL服务启动失败的快速解决方法
-
CentOS 6.1源码安装MySQL 5.5.21
-
Centos安装桌面环境(一个命令搞定) 博客分类: 服务器 groupinstallyumwindowgnomedesktop
-
Centos安装桌面环境(一个命令搞定) 博客分类: 服务器 groupinstallyumwindowgnomedesktop
-
centos7的linux几个常用启动命令
-
CentOS 7安装.NetCore
-
CENTOS7 下配置PHP + MySQL + Nginx开发环境
-
centOS 一键php环境安装-php博弈_PHP教程