前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【笔记】Linux安装Nginx相关步骤,备忘

【笔记】Linux安装Nginx相关步骤,备忘

作者头像
无道
发布2021-07-19 15:59:39
2830
发布2021-07-19 15:59:39
举报
文章被收录于专栏:无道编程无道编程

1. 前言

本来尝试了Docker的,但是由于一些原因,不太方便,还是选择原生 的nginx安装

2. 下载

下载:http://nginx.org/en/download.html

下载后,解压到一个目录,此目录随便,因为之后要编译

编译代码:

代码语言:javascript
复制
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module

其实本文最主要的目的就是想记录上面的参数,方便万一以后需要使用

说明:

  • --prefix=是安装的nginx目录
  • --usergroup需要提前创建www组和用户

acme.sh申请ssl,并且一些nginx配置ssl的参考,请见:

https://www.misiai.com/articles/30.html

3.systemctl

代码语言:javascript
复制
 vim /usr/lib/systemd/system/nginx.service

粘贴:

代码语言:javascript
复制
[Unit] 
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target 
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
代码语言:javascript
复制
systemctl daemon-reload
systemctl start nginx.service

汇总脚本

代码语言:javascript
复制
#!/bin/sh
groupadd www
useradd www -g www -s /sbin/nologin

sudo wget http://nginx.org/download/nginx-1.20.1.tar.gz

sudo tar zxvf nginx-1.20.1.tar.gz

cd nginx-1.20.1

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --with-http_gzip_static_module --with-http_sub_module --with-http_v2_module

make && make install


sudo tee  /usr/lib/systemd/system/nginx.service <<-'EOF'
[Unit] 
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target 
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF

sudo systemctl daemon-reload
sudo systemctl start nginx.service
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-07-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 前言
  • 2. 下载
  • 3.systemctl
  • 汇总脚本
相关产品与服务
SSL 证书
腾讯云 SSL 证书(SSL Certificates)为您提供 SSL 证书的申请、管理、部署等服务,为您提供一站式 HTTPS 解决方案。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档