Ubuntu 18.04 安装 Nginx

我们两清 提交于 2020-05-04 03:39:14

一、安装包安装

安装Nginx

sudo apt-get update
sudo apt-get install nginx
名称 目录
配置文件 /etc/nginx/nginx.conf
程序文件 /usr/sbin/nginx
日志 /varlog/nginx
默认虚拟主机 /var/www/html

启动Nginx 服务

sudo systemctl start nginx

开机自动启动nginx 服务

sudo systemctl enable nginx

关闭开机自动启动nginx 服务

sudo systemctl disable nginx

打开浏览器, 在地址栏输入127.0.0.1 or localhost, 出现Nginx 经典网页即表示成功。也可以用Nginx 命令去测试

sudo nginx -t

查看端口

sudo lsof -i:80

测试nginx.conf文件

/usr/sbin/nginx -t -c /etc/nginx/nginx.conf

 

二、源代码安装

命令

$cd /usr/local  //进入local目录
$wget http://nginx.org/download/nginx1.12.1.tar.gz  // 指定版本在线安装
$tar -zxvf nginx-1.12.1.tar.gz //解压缩
$sudo apt-get install build-essential libtool libpcre3 libpcre3-dev zlib1g-dev openssl libssl-dev //安装依赖库
$cd nginx-1.12.1
$./configure --prefix=/usr/local/nginx  --with-http_ssl_module
$make
$make install

–with-http_ssl_module主要是配置https时用到,不加上这个参数的话到时启动https会找不到ssl模块

名称 目录
配置文件 /usr/local/nginx/conf/nginx.conf
程序文件 /usr/local/nginx/sbin/nginx
日志 /var/log/nginx
默认虚拟主机 /var/www/

启动

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

conf配置文件示例

server {
    listen      80;
    server_name localhost;
    index index.html index.htm index.php;
    root /var/www/html/statium;
    location / {
        root /var/www/html/statium;
        try_files $uri $uri/ /index.html last;
        index index.html;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root html;
    }
}

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!