Linux下安装Nginx

1.查看Linux系统版本

```$lsb_release -a #Ubuntu下执行

Distributor ID: Ubuntu

Description:    Ubuntu 16.04.2 LTS

Release:    16.04

Codename:  xenial```

```$cat /etc/redhat-release #CentOS下执行

CentOS Linux release 7.3.1611 (Core)```

2.安装Nginx

  2.1 CentOS下最简单的方法是从EPEL软件库源上下载安装

```$sudo yum install epel-release

$yum install nginx ```

 2.2Ubuntu 下安装nginx

```$sudo apt-get update

$sudo apt-get install nginx```

安装中发现错误,查看错误,是因为端口80被占用了,继续查看端口被那个进程占用,发现是以前安装的apache2. 先kill进程,再次安装。

```$systemctl status nginx.service

nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)

$sudo netstat -tunlp|grep 80

tcp6      0      0 :::80      :::*      LISTEN      1192/apache2 

$sudo kill 1192

$sudo apt-get install nginx

$sudo netstat -tunlp|grep 80

tcp        0      0 0.0.0.0:80    0.0.0.0:*      LISTEN      6827/nginx -g daemo

tcp6      0      0 :::80          :::*            LISTEN      6827/nginx -g daemo```

3. 启动Nginx

3.1 Ubuntu下安装nginx后会自动启动,无需再手动执行,可以把nginx加到系统启动服务

    ``` $systemctl enable nginx #设置开机启动```

3.2 CentOS下需手动启动

   ``` $systemctl start nginx #启用Nginx

    $systemctl enable nginx #设置开机启动```

可以通过浏览器访问服务器地址http://ip:80来看看nginx运行情况:

Nginx有几个基本功能,我们这里主要是用到2个:

静态HTTP服务器

This is the default index.html page that is distributed with nginx on Fedora. It is located in /usr/share/nginx/html.

静态网页放在指定目录就可以了。

基于反向代理的虚拟主机功能

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容