下载Nginx源码
手动下载并上传到服务器
源码下载链接 http://nginx.org/download/nginx-1.18.0.tar.gz
服务器直接下载
$: cd temp
$: wget http://nginx.org/download/nginx-1.18.0.tar.gz
编译并安装
解压nginx源码包
$: tar -xvzf nginx-1.18.0.tar.gz
生成Makefile
文档:Building nginx from Sources
$: cd nginx-1.18.0
# 默认直接./configure 不需要跟后面的参数,如果需要修改配置在后面加参数
$: ./configure --prefix=/usr/local/nginx --with-http_ssl_module
开始编译
$: sudo make clean
$: sudo make
安装
$: sudo make install
# 创建软连接 直接使用命令 nginx
$: sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
启动服务
# 验证 nginx 是否正常
$: nginx -t
$: sudo nginx
设置开机自启
[Unit]
Description = nginx - high performance web server
After = network.target
[Service]
User = root
Type = forking
ExecStart = /usr/local/nginx/sbin/nginx
ExecReload = /usr/local/nginx/sbin/nginx -s reload
ExecStop = /usr/local/nginx/sbin/nginx -s stop
Execenable = /usr/local/nginx/sbin/nginx
[Install]
WantedBy = multi-user.target
$: sudo systemctl enable nginx.service
$: sudo systemctl start nginx.service
打开浏览器输入:http://ip 查看是否启动
修改默认端口
/usr/local/nginx/conf/nginx.conf
server {
...
listen 81;
server_name localhost;
...
}
注:使用命令安装的 nginx
修改nginx.conf
并不会生效,需要修改 /etc/nginx/sites-avaliable/default
文件中的配置
安装编译环境
如果上面的 make
make intall
出现错误,需要先安装 nginx 的编译环境
# Debian Ubuntu
$: sudo apt-get install gcc make
$: sudo apt-get install libpcre3 libpcre3-dev
$: sudo apt-get install zlib1g-dev
$: sudo apt-get install openssl libssl-dev
# opensuse15.5 Leap
$: sudo zypper install gcc make zlib-devel pcre-devel openssl-devel
在安装 libssl-dev 的时候若出现报错:
【解决办法】 降级 libssl 解决依赖关系,通过 aptitude 安装:
$: sudo apt-get install aptitude
$: sudo aptitude install libssl-dev
标签:编译,nginx,local,make,sudo,Nginx,usr,install,安装
From: https://blog.51cto.com/soldatyxd/8583845