Ubuntu下安装Nginx
一、系统基本信息查看1、查看Ubuntu版本信息:
使用命令:cat /proc/version 查看~$ cat /proc/versionlinux version 4.15.0-106-generic (buildd@lcy01-amd64-016) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #107-Ubuntu SMP Thu Jun 4 11:27:52 UTC 2020
从查看的结果很明显发现当前的版本信息为: (Ubuntu 7.5.0-3ubuntu1~18.04),
2、查看系统中是不是已经安装了Nginx
这里直接使用如下命令即可:
ltwuyanlong@ubuntu:~$ nginx -v
Command 'nginx' not found, but can be installed with:sudo apt install nginx-coresudo apt install nginx-extrassudo apt install nginx-fullsudo apt install nginx-light
二、开始安装Ngnix1、查看80端口占用情况
$ lsof -i tcp:80
2、更新apt
$ sudo apt update
3、安装nginx
$sudo apt-get install nginx
Ubuntu安装之后的文件结构大致为:所有的配置文件都在**/etc/nginx下,并且每个虚拟主机
已经安排在了
/etc/nginx/sites-available**下
安装成功之后:
xxx@ubuntu:/etc/nginx$ ls -ltotal 64drwxr-xr-x 2 root root 4096 Jan 10 11:18 conf.d-rw-r--r-- 1 root root 1077 Apr52018 fastcgi.conf-rw-r--r-- 1 root root 1007 Apr52018 fastcgi_params-rw-r--r-- 1 root root 2837 Apr52018 koi-utf-rw-r--r-- 1 root root 2223 Apr52018 koi-win-rw-r--r-- 1 root root 3957 Apr52018 mime.typesdrwxr-xr-x 2 root root 4096 Jan 10 11:18 modules-availabledrwxr-xr-x 2 root root 4096 Jun 22 04:56 modules-enabled-rw-r--r-- 1 root root 1482 Apr52018 nginx.conf-rw-r--r-- 1 root root180 Apr52018 proxy_params-rw-r--r-- 1 root root636 Apr52018 scgi_paramsdrwxr-xr-x 2 root root 4096 Jun 22 04:56 sites-availabledrwxr-xr-x 2 root root 4096 Jun 22 04:56 sites-enableddrwxr-xr-x 2 root root 4096 Jun 22 04:56 snippets-rw-r--r-- 1 root root664 Apr52018 uwsgi_params-rw-r--r-- 1 root root 3071 Apr52018 win-utf
程序文件在**/usr/sbin/nginx**,日志放在了**/var/log/nginx**中
xxx@ubuntu:/var/log/nginx$ lsaccess.logerror.log
并已经在/etc/init.d/下创建了启动脚本nginx
xxx@ubuntu:/etc/init.d$ lsacpidApportconsole-setup.shdbusgrub-commonkeyboard-setup.shnginxpppd-DNSsanedufwx11-commonalsa-utilsavahi-daemoncrondns-cleanhwclock.shkmodopen-vm-toolsprocpsspeech-dispatcherunattended-upgradesanacronbluetoothcupsDockerirqbalancenetworkingplymouthrsyncspice-vdagentuuiddapparmorcgroupfs-mountcups-browsedgdm3kerneloopsnetwork-managerplymouth-logrsyslogudevwhoopsie
在这下面确实创建了启动脚本 。
默认的虚拟主机的目录设置在了**/var/www/nginx-default **(有的版本 默认的虚拟主机的目录设置在了/var/www, 请参考
/etc/nginx/sites-available里的配置) 。
4、启动Nginx
xxx@ubuntu:~$ sudo /etc/init.d/nginx start [sudo] password for xxx: [ ok ] Starting nginx (via systemctl): nginx.service.
在启动之后在Ubuntu上面的浏览器中输入地址:
http://localhost/,假如输出如下的信息就证明启动成功了 。
Welcome to nginx!If you see this page, the nginx web server is successfully installed and working. Further configuration is required.For online documentation and support please refer to nginx.org.Commercial support is available at nginx.com.Thank you for using nginx.
假如要在你客户端浏览器中访问的话需要使用安装Nginx服务器的IP地址进行访问 。例如,首先查询IP地址:
xxx@ubuntu:~$ ip addr1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope hostvalid_lft forever preferred_lft forever2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000link/ether 00:0c:29:81:e9:1b brd ff:ff:ff:ff:ff:ffinet 192.168.6.128/24 brd 192.168.6.255 scope global dynamic noprefixroute ens33valid_lft 1205sec preferred_lft 1205secinet6 fe80::5e9d:43aa:1a64:8fd/64 scope link noprefixroutevalid_lft forever preferred_lft forever3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group defaultlink/ether 02:42:b7:2f:42:3b brd ff:ff:ff:ff:ff:ffinet 172.17.0.1/16 brd 172.17.255.255 scope global docker0valid_lft forever preferred_lft forever
获取,如上图所示,查询到的IP为: 192.168.6.128.之后直接在浏览器中输入这个IP回车之后,反馈的信息为:
Welcome to nginx!If you see this page, the nginx web server is successfully installed and working. Further configuration is required.For online documentation and support please refer to nginx.org.Commercial support is available at nginx.com.Thank you for using nginx.
启动可能导致的问题:
如果不能访问,先不要继续,看看是什么原因,解决之后再继续 。
推荐阅读
- linux安装安全狗
- PhotoShop 2021 九月最新版本安装使用测试
- 智能电视如何利用U盘安装第三方应用?附小程序密码
- linux高性能服务器开发十大必须掌握的核心技术
- linux之chroot命令
- 制作网线不求人,内行人教你徒手安装水晶头,省心又省力
- Linux中su,sudo,sudo su,sudo -i命令的使用和区别
- 最强的漏洞扫描工具Nessus安装教程
- win10win10双系统怎么装,window10双系统怎么安装-
- 如何安装打印机驱动程序