【笔记】Linux安装Nginx相关步骤,备忘
无道
2021-07-16
3 条评论
一些备忘
阅读3346
手机阅读
1. 前言
本来尝试了Docker的,但是由于一些原因,不太方便,还是选择原生 的nginx安装
2. 下载
下载:http://nginx.org/en/download.html
下载后,解压到一个目录,此目录随便,因为之后要编译
编译代码:
./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目录--user
和group
需要提前创建www组和用户
acme.sh申请ssl,并且一些nginx配置ssl的参考,请见:
https://www.misiai.com/articles/30.html
3.systemctl
vim /usr/lib/systemd/system/nginx.service
粘贴:
[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
systemctl daemon-reload
systemctl start nginx.service
汇总脚本
#!/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
全文完 [
支付宝打赏
微信打赏
]
有帮助?打赏


非特殊说明,本博所有文章均为博主原创。如若转载,请注明出处:https://misiyu.cn/article/175.html
It's me
昵称:无道
坐标:成都
性别:
一个人,一介学生社会人,一个儿子~ 愿你我都被世界温暖以待
最新评论
点击排行
随机标签
@[200],大佬说的对啊~~~
大佬现在在哪高就?你的Powered By好像写错了吧~~不是你自己开发的吗?怎么写的腾讯云?
@[199],当然可以,但是一般来说这些包管理工具都不会是最新版本。
另外,对于编程这行来说肯定最好是知其然,知其所以然。
弱弱地问一句,yum和apt-get这些不能直接装好吗?233
咳,我是懒得去下载的。