Centos nginx 安装 源码方式安装
以 yum 方式安装 Nginx https://andyoung.blog.csdn.net/article/details/118802486
安装所需插件
1、安装gcc
gcc是linux下的编译器在此不多做解释,感兴趣的小伙伴可以去查一下相关资料,它可以编译 C,C++,Ada,Object C和Java等语言
命令:查看gcc版本
gcc -v
一般阿里云的centOS7里面是都有的,没有安装的话会提示命令找不到,
安装命令:
yum -y install gcc
2、pcre、pcre-devel安装
pcre是一个perl库,包括perl兼容的正则表达式库,nginx的http模块使用pcre来解析正则表达式,所以需要安装pcre库。
安装命令:
yum install -y pcre pcre-devel
3、zlib安装
zlib库提供了很多种压缩和解压缩方式nginx使用zlib对http包的内容进行gzip,所以需要安装
安装命令:
yum install -y zlib zlib-devel
4、安装openssl
openssl是web安全通信的基石
安装命令:
yum install -y openssl openssl-devel
安装nginx
1、下载nginx安装包
在官网 http://nginx.org/en/download.html找一个最新的 安装包
比如:
wget http://nginx.org/download/nginx-1.21.3.tar.gz
2、把压缩包解压到usr/local/java
tar -zxvf nginx-1.21.3.tar.gz
3、切换到cd /usr/local/java/nginx-1.21.3下面
执行三个命令:
./configuremakemake install
4、切换到/usr/local/nginx
安装目录
5、配置nginx的配置文件nginx.conf文件,主要也就是端口
可以按照自己服务器的端口使用情况来进行配置
ESC键,wq!强制保存并退出
6、启动nginx服务
切换目录到/usr/local/nginx/sbin下面
启动nginx命令:
./nginx
7、查看nginx服务是否启动成功
ps -ef | grep nginx
8、访问你的服务器IP
显示
说明安装和配置都没问题OK了
#user nobody;
worker_processes 1; #工作进程:数目。根据硬件调整,通常等于cpu数量或者2倍cpu数量。#错误日志存放路径
error_log /var/log/nginx/error.log;
error_log /var/log/nginx/error.log notice;
error_log /var/log/nginx/error.log info;pid /run/nginx.pid; # nginx进程pid存放路径events {worker_connections 1024; # 工作进程的最大连接数量
}http {include mime.types; #指定mime类型,由mime.type来定义default_type application/octet-stream;# 日志格式设置#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 logs/access.log main; #用log_format指令设置日志格式后,需要用access_log来指定日志文件存放路径sendfile on; #指定nginx是否调用sendfile函数来输出文件,对于普通应用,必须设置on。如果用来进行下载等应用磁盘io重负载应用,可设着off,以平衡磁盘与网络io处理速度,降低系统uptime。#tcp_nopush on; #此选项允许或禁止使用socket的TCP_CORK的选项,此选项仅在sendfile的时候使用#keepalive_timeout 0; #keepalive超时时间keepalive_timeout 65;#gzip on; #开启gzip压缩服务#虚拟主机server {listen 80; #配置监听端口号server_name localhost; #配置访问域名,域名可以有多个,用空格隔开#charset koi8-r; #字符集设置#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#错误跳转页#error_page 404 /404.html; # redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ { #请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。# root html; #根目录# fastcgi_pass 127.0.0.1:9000; #请求转向定义的服务器列表# fastcgi_index index.php; # 如果请求的Fastcgi_index URI是以 / 结束的, 该指令设置的文件会被附加到URI的后面并保存在变量$fastcig_script_name中# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl; #监听端口# server_name localhost; #域名# ssl_certificate cert.pem; #证书位置# ssl_certificate_key cert.key; #私钥位置# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; #密码加密方式# ssl_prefer_server_ciphers on; # ssl_prefer_server_ciphers on; ## location / {# root html;# index index.html index.htm;# }#}}
使用 systemctl 启动、开机自启
新建启动文件vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=mixed
PrivateTmp=true[Install]
WantedBy=multi-user.target
注意修改NGINX 配置文件 pid 文字 以及 将nginx 二进制文件软链接到
/usr/sbin/nginx
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
systemctl 启动
chmod +x /usr/lib/systemd/system/nginx.service
systemctl daemon-reload
systemctl restart nginx
systemctl 开机自启
···
systemctl restart nginx
···
Centos nginx 安装 源码方式安装相关推荐
- 源码方式安装的nginx注册到systemctl管理
用源码方式安装的nginx每次都要进入安装目录才能进行启动.重启.停止操作,使用yum install nginx方式安装的话会自动注册到systemctl管理中,源码方式安装的nginx注册到sys ...
- CentOS 7.6源码编译安装gluster 6.1
CentOS 7.6源码编译安装gluster 6.1 一.测试目的 测试使用源1. 码编译进行gluster集群的安装配置: 2. 测试使用源码编译生成RPM包进行gluster集群的安装配置: 二 ...
- CentOS 7上源码编译安装和配置LNMP Web+phpMyAdmin服务器环境
什么是LNMP? LNMP(别名LEMP)是指由Linux, Nginx, MySQL/MariaDB, PHP/Perl/Python组合成的动态Web应用程序和服务器,它是一组Web应用程序的基础 ...
- CentOS 6.5源码编译安装MySQL 5.6
对于服务器的环境,个人觉得还是源码编译安装的非常靠谱,假如有服务器要变更,直接rm掉安装目录即可.有些人喜欢yum安装,但是在卸载yum remove的时候,一不小心,就卸载了一个基础库,导致系统的s ...
- CentOS 6.5源码包安装MySQL
#源码包安装MySQL数据库 [root@domain ]# yum -y install gcc gcc-c++ autoconf automake zlib* libxml* ncurses-de ...
- 04_MySQL笔记-介绍-rpm安装/源码编译安装MySQL-远程连接
文章目录 介绍 rpm方式安装MySQL 源码编译安装MySQL 一键安装脚本 远程连接 个人博客 https://blog.csdn.net/cPen_web 介绍 MySQL MySQL是一个数据 ...
- CentOS 安装MySQL5.7 源码方式安装
MySQL rpm方式安装:https://www.cnblogs.com/deverz/p/9560403.html 1.卸载已经安装的MySQL yum list installed mysqlr ...
- 虚拟机安装mysql5.7.20_虚拟机环境下CentOS 7 中安装Mysql 5.7.24(源码方式安装)
偿试过用yum安装的都失败了,原因是服务启动时报错,偿试了多种解决办法,均不成功.然用源码方法却成功了,下面就介绍记录一下安装步骤. 1 安装cmake工具 yum install -y cmake ...
- centos 7 源码方式安装mysql5.6
mysql安装:参考文章1 mysql编译报错:参考文章2 1.首先,创建目录,输入命令: mkdir /usr/local/mysql mkdir /usr/local/mysql/data 2.接 ...
最新文章
- Jsp/eclipse 链接oracle数据库
- Perl学习笔记(2)
- web python php golang_python go 语言完成最简单的web应用
- 关于JUnit5 你必须知道的(二)JUnit 5的新特性
- ajax发送请求-同步和异步
- 简单的数据结构题(多项式、拉格朗日插值、线段树)
- thinkphp导航高亮的方法
- Jeecg平台扩展性不好的地方收集启动。
- 随机变量统计独立性的相关证明
- java JButton计算器布局
- JDK和CGLIB动态代理的区别
- 使用python批量压缩图片文件
- 转:亚熟男 我们该拿你怎么办?
- 使用NLTK对文档进行分句
- 左耳朵耗子:我看ChatGPT,为啥谷歌掉了千亿美金
- java零项目经验,找工作前该如何准备项目?面试时又该怎么说?
- Thinkphp内核SEO按天关键词计费排名查询系统源码
- 查看患者信息java_Java通过反射查看类的信息示例
- 报表引擎终于做出来了!!!!!参考了根兄的文档。
- linux for循环套for循环格式_FOR循环指令案例详解
热门文章
- MPB:湖南师大尹佳组-​乳酸菌对酸和胆碱盐的耐受能力
- 微生物组实验手册计划正式启动、诚邀同行共同打造本领域方法百科全书
- 基础002. Editplus编辑远程文件
- 判断三角形java代码_小猿圈Java循环嵌套语法的使用介绍
- pandas使用query函数查询指定日期索引对应的dataframe数据行(select rows using a single date in dataframe)
- python使用matplotlib可视化线图(line plot)、在可视化图像中的指定位置添加横线(add horizontal line in matplotlib plot)
- R语言plotly可视化:可视化直方图、归一化的直方图、水平直方图、互相重叠的直方图、堆叠的直方图、累积直方图、通过bingroup参数设置多个直方图使用相同的bins设置、自定义直方图条形的间距
- pandas索引复合索引dataframe数据、索引其中多个水平(level)的多个数据行(index rows from different levels)、使用元组tuple表达复合索引的指定行
- pandas中dataframe默认不显示所有的数据行(中间省略)、使用option_context函数自定义设置单个dataframe允许显示的行的个数、set_option函数全局设置显示行的个数
- R语言使用coin包应用于分类变量独立性问题的置换检验(permutation tests)、使用普通卡方检验chisq.test函数和置换近似卡方检验chisq.test函数、检验分类变量的独立性