Nginx安装
本文选用apt的方式快速进行nginx的安装。
注意:阿里云的apt仓库可能不是最新的,因此,需要进行更新,否则会报错"Unable to locate package nginx",因此,一旦出现这个问题,请先进行更新
sudo apt-get update
root@m01:~/nginx-1.13.8/conf# sudo apt-get update
Hit:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial InRelease
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates InRelease [109 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security InRelease [107 kB]
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main Sources [320 kB]
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/universe Sources [221 kB]
Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 Packages [849 kB]
Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main i386 Packages [763 kB]
Get:8 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main Translation-en [347 kB]
Get:9 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/universe amd64 Packages [683 kB]
Get:10 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/universe i386 Packages [624 kB]
Get:11 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/universe Translation-en [276 kB]
Get:12 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/main Sources [133 kB]
Get:13 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/universe Sources [74.0 kB]
Get:14 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/main amd64 Packages [554 kB]
Get:15 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/main i386 Packages [479 kB]
Get:16 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/main Translation-en [234 kB]
Get:17 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/universe amd64 Packages [370 kB]
Get:18 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/universe i386 Packages [317 kB]
Get:19 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-security/universe Translation-en [141 kB]
Fetched 6,601 kB in 2s (3,144 kB/s)
Reading package lists... Done
sudo apt-get install nginx
root@m01:~/nginx-1.13.8/conf# sudo apt-get install nginx
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
linux-headers-4.4.0-87 linux-headers-4.4.0-87-generic linux-image-4.4.0-87-generic linux-image-extra-4.4.0-87-generic
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libvpx3 libxpm4 libxslt1.1 nginx-common nginx-core
Suggested packages:
libgd-tools fcgiwrap nginx-doc ssl-cert
The following NEW packages will be installed:
fontconfig-config fonts-dejavu-core libfontconfig1 libgd3 libvpx3 libxpm4 libxslt1.1 nginx nginx-common nginx-core
0 upgraded, 10 newly installed, 0 to remove and 109 not upgraded.
Need to get 2,715 kB of archives.
After this operation, 8,752 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/main amd64 fonts-dejavu-core all 2.35-1 [1,039 kB]
Get:2 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 fontconfig-config all 2.11.94-0ubuntu1.1 [49.9 kB]
Get:3 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 libfontconfig1 amd64 2.11.94-0ubuntu1.1 [131 kB]
Get:4 http://mirrors.cloud.aliyuncs.com/ubuntu xenial/main amd64 libvpx3 amd64 1.5.0-2ubuntu1 [732 kB]
Get:5 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 libxpm4 amd64 1:3.5.11-1ubuntu0.16.04.1 [33.8 kB]
Get:6 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 libgd3 amd64 2.1.1-4ubuntu0.16.04.10 [126 kB]
Get:7 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 libxslt1.1 amd64 1.1.28-2.1ubuntu0.1 [145 kB]
Get:8 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 nginx-common all 1.10.3-0ubuntu0.16.04.2 [26.6 kB]
Get:9 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 nginx-core amd64 1.10.3-0ubuntu0.16.04.2 [428 kB]
Get:10 http://mirrors.cloud.aliyuncs.com/ubuntu xenial-updates/main amd64 nginx all 1.10.3-0ubuntu0.16.04.2 [3,490 B]
Fetched 2,715 kB in 0s (3,040 kB/s)
Preconfiguring packages ...
Selecting previously unselected package fonts-dejavu-core.
(Reading database ... 133007 files and directories currently installed.)
Preparing to unpack .../fonts-dejavu-core_2.35-1_all.deb ...
Unpacking fonts-dejavu-core (2.35-1) ...
Selecting previously unselected package fontconfig-config.
Preparing to unpack .../fontconfig-config_2.11.94-0ubuntu1.1_all.deb ...
Unpacking fontconfig-config (2.11.94-0ubuntu1.1) ...
Selecting previously unselected package libfontconfig1:amd64.
Preparing to unpack .../libfontconfig1_2.11.94-0ubuntu1.1_amd64.deb ...
Unpacking libfontconfig1:amd64 (2.11.94-0ubuntu1.1) ...
Selecting previously unselected package libvpx3:amd64.
Preparing to unpack .../libvpx3_1.5.0-2ubuntu1_amd64.deb ...
Unpacking libvpx3:amd64 (1.5.0-2ubuntu1) ...
Selecting previously unselected package libxpm4:amd64.
Preparing to unpack .../libxpm4_1%3a3.5.11-1ubuntu0.16.04.1_amd64.deb ...
Unpacking libxpm4:amd64 (1:3.5.11-1ubuntu0.16.04.1) ...
Selecting previously unselected package libgd3:amd64.
Preparing to unpack .../libgd3_2.1.1-4ubuntu0.16.04.10_amd64.deb ...
Unpacking libgd3:amd64 (2.1.1-4ubuntu0.16.04.10) ...
Selecting previously unselected package libxslt1.1:amd64.
Preparing to unpack .../libxslt1.1_1.1.28-2.1ubuntu0.1_amd64.deb ...
Unpacking libxslt1.1:amd64 (1.1.28-2.1ubuntu0.1) ...
Selecting previously unselected package nginx-common.
Preparing to unpack .../nginx-common_1.10.3-0ubuntu0.16.04.2_all.deb ...
Unpacking nginx-common (1.10.3-0ubuntu0.16.04.2) ...
Selecting previously unselected package nginx-core.
Preparing to unpack .../nginx-core_1.10.3-0ubuntu0.16.04.2_amd64.deb ...
Unpacking nginx-core (1.10.3-0ubuntu0.16.04.2) ...
Selecting previously unselected package nginx.
Preparing to unpack .../nginx_1.10.3-0ubuntu0.16.04.2_all.deb ...
Unpacking nginx (1.10.3-0ubuntu0.16.04.2) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Setting up fonts-dejavu-core (2.35-1) ...
Setting up fontconfig-config (2.11.94-0ubuntu1.1) ...
Setting up libfontconfig1:amd64 (2.11.94-0ubuntu1.1) ...
Setting up libvpx3:amd64 (1.5.0-2ubuntu1) ...
Setting up libxpm4:amd64 (1:3.5.11-1ubuntu0.16.04.1) ...
Setting up libgd3:amd64 (2.1.1-4ubuntu0.16.04.10) ...
Setting up libxslt1.1:amd64 (1.1.28-2.1ubuntu0.1) ...
Setting up nginx-common (1.10.3-0ubuntu0.16.04.2) ...
insserv: can not symlink(../init.d/aegis, ../rc2.d/S02aegis): File exists
insserv: can not symlink(../init.d/aegis, ../rc3.d/S02aegis): File exists
insserv: can not symlink(../init.d/aegis, ../rc4.d/S02aegis): File exists
insserv: can not symlink(../init.d/aegis, ../rc5.d/S02aegis): File exists
Setting up nginx-core (1.10.3-0ubuntu0.16.04.2) ...
Setting up nginx (1.10.3-0ubuntu0.16.04.2) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for systemd (229-4ubuntu21.2) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
安装好的nginx文件结构
/usr/sbin/nginx:主程序,运行的程序一般放在/usr/sbin或者/usr/bin
/etc/nginx:存放配置文件,Linux系统的配置文件一般放在/etc
/usr/share/nginx:存放静态文件
/var/log/nginx:存放日志,日志一般放在/var/log
如果要更清楚Nginx的配置项放在什么地方,可以打开/etc/nginx/nginx.conf,查看加载的是哪个配置文件,可以用这个命令sudo nginx -t或者ps -ef | grep nginx
通过apt-get这种方式安装的,会自动创建服务,会自动在/etc/init.d/nginx新建服务脚本,然后就可以使用sudo service nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}的命令启动。
还有一个好处,创建好的文件由于放在/usr/sbin目录下,所以能直接在终端中使用nginx命令而无需指定路径。
另外 直接使用 nginx -s reload 可以使配置文件加载
yum
对应yum要简单说一下,
如果是阿里云centos7的话,可以通过yum update,然后进行安装
1、添加源
默认情况Centos7中无Nginx的源,最近发现Nginx官网提供了Centos的源地址。因此可以如下执行命令添加源:
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2、安装Nginx
通过yum search nginx看看是否已经添加源成功。如果成功则执行下列命令安装Nginx。
sudo yum install -y nginx
3、启动Nginx并设置开机自动运行
sudo systemctl start nginx.service
sudo systemctl enable nginx.service