Linux环境Nginx安装部署

如果你不相信努力和时光,那么成果就会是第一个选择辜负你的。不要去否定你自己的过去,也不要用你的过去牵扯你现在的努力和对未来的展望。不是因为拥有希望你才去努力,而是去努力了,你才有可能看到希望的光芒。Linux环境Nginx安装部署,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

前言

本栏主要记录一些常用的中间件docker部署方式,具体如下:

  1. Linux安装docker(简单粗暴,复制即用)
  2. Linux环境使用docker安装MySQL(简单粗暴,复制即用)
  3. Linux环境docker安装redis(简单粗暴,复制即用)
  4. Linux环境Nginx安装部署
  5. docker安装部署Elasticsearch(ES)以及相关配置
  6. Linux环境docker安装Nacos(简单粗暴,复制即用)
  7. Linux环境docker安装Neo4j,以及Neo4j新手入门教学(超详细版本)

如果没有gcc环境,需要安装gcc:

yum install gcc-c++

安装依赖

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

进入文件夹

cd  /usr/local

下载安装包

wget http://nginx.org/download/nginx-1.18.0.tar.gz

解压安装包

tar -xvf nginx-1.18.0.tar.gz  
解压之后不需要重新命名直接进去解压目录

# 进入nginx-1.18.0目录 
cd /usr/local/nginx-1.18.0

执行命令

./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf  --error-log-path=/usr/local/nginx/logs/error.log --pid-path=/usr/local/nginx/logs/nginx.pid  --http-log-path=/usr/local/nginx/logs/access.log --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module

#prefix= 指向安装目录(编译安装)
#conf-path= 指向配置文件(nginx.conf)
#error-log-path= 指向错误日志目录
#pid-path= 指向pid文件(nginx.pid)
#http-log-path= 设定access log路径
#with-http_gzip_static_module 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
#with-http_stub_status_module 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
#with-http_ssl_module 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl)

执行命令

make

执行make install命令

make install

启动nginx

 cd  /usr/local/nginx/sbin
./nginx

查看nginx进程

ps -ef | grep nginx

打开阿里云的网路安全组开放80端口

在浏览器访问服务器ip

编写开机自动启动脚本

vim /lib/systemd/system/nginx.service

按i编辑 把下面复制进去 按esc建 再按shift+:键 wq 保存退出

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
#自己nginx启动的pid文件自己找到文件目录
PIDFile=/usr/local/nginx/logs/nginx.pid
#自己nginx的启动文件 
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
#默认
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

启动

systemctl start nginx.service

设置开机自启

systemctl enable nginx.service

出现以下提示表示设置成功

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

停止开机自启动

systemctl disable nginx.service

查看服务当前状态

systemctl status nginx.service

重新启动服务

systemctl reload nginx.service

停止服务

systemctl stop nginx.service

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之家整理,本文链接:https://www.bmabk.com/index.php/post/202823.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之家——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!