Ubuntu编译安装Nginx
时间: 2024-02-02 09:52:01 浏览: 126
1. 下载Nginx源码包
在官网上下载最新的Nginx源码包,下载地址为:http://nginx.org/en/download.html
2. 安装编译工具
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
sudo apt-get install libssl-dev
3. 解压源码包
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
4. 编译
./configure
make
sudo make install
5. 配置Nginx
sudo mkdir /usr/local/nginx/conf/vhosts
sudo nano /usr/local/nginx/conf/nginx.conf
在http模块内添加以下内容
include vhosts/*.conf;
sudo nano /usr/local/nginx/conf/vhosts/default.conf
添加以下内容:
server {
listen 80;
server_name localhost;
root /usr/local/nginx/html;
index index.html index.htm;
}
6. 启动Nginx
sudo /usr/local/nginx/sbin/nginx
7. 测试Nginx
在浏览器中输入http://localhost,如果能看到Nginx的欢迎页面,则表示安装成功。
阅读全文