ubuntu安装nginx教程
1. 安装nginx的依赖包
# 查看zlib是否安装
dpkg -l | grep zlib
# 解决依赖包openssl安装
sudo apt-get install openssl libssl-dev
# 解决依赖包pcre安装
sudo apt-get install libpcre3 libpcre3-dev
# 解决依赖包zlib安装
sudo apt-get install zlib1g-de
2. 下载nginx
# 下载nginx
wget /download/nginx-1.13.
# 解压nginx
tar -xzvf nginx-1.13.
# 重命名⽂件夹
mv nginx-1.13.1 nginx
# 移动⽂件夹到ubuntu常见软件⽬录下
mv nginx/ /usr/local/
3. 安装nginx
# 配置nginx
cd /usr/local/nginx
sudo ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module # 编译nginx
sudo make
# 安装nginx
sudo make install
4. 检查nginx是否安装成功
cd /usr/local/nginx/sbin
./nginx -t
如果结果结果显⽰:
nginx: the configuration file /usr/local/nginx/f syntax is ok
nginx: configuration file /usr/local/nginx/f test is successful
5. 启动nginx
# ⽅法1
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/f
# ⽅法2
cd /usr/local/nginx/sbin
./nginx
通过本地访问⼀下⽹站 127.0.0.1界⾯为
可能遇到的问题
1、软件源⽆法获取:
东北⼤学清华⼤学
打开 sudo vim /etc/apt/source.list
deb-src mirror .neu.edu /ubuntu/ xenial main restricted #Added by software-properties
deb mirror .neu.edu /ubuntu/ xenial main restricted
deb-src mirror .neu.edu /ubuntu/ xenial restricted multiverse universe #Added by software-properties
deb mirror .neu.edu /ubuntu/ xenial-updates main restricted
deb-src mirror .neu.edu /ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb mirror .neu.edu /ubuntu/ xenial universe
deb mirror .neu.edu /ubuntu/ xenial-updates universe
deb mirror .neu.edu /ubuntu/ xenial multiverse
deb mirror .neu.edu /ubuntu/ xenial-updates multiverse
deb mirror .neu.edu /ubuntu/ xenial-backports main restricted universe multiverse
deb-src mirror .neu.edu /ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb archive .canonical /ubuntu xenial partner
deb-src archive .canonical /ubuntu xenial partner
deb mirror .neu.edu /ubuntu/ xenial-security main restricted
deb-src mirror .neu.edu /ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb mirror .neu.edu /ubuntu/ xenial-security universe
deb mirror .neu.edu /ubuntu/ xenial-security multiverse
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial main restricted
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial-updates main restricted
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial universe
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial-updates universe
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial multiverse
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial-updates multiverseubuntu安装教程
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial-backports main restricted universe multiverse
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial-security main restricted
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial-security universe
deb mirrors.tuna.tsinghua.edu/ubuntu/ xenial-security multiverse
sudo apt-get update更新⼀下就搞定
2、nginx: [emerg] getpwnam(“www”) failed错误
#/usr/sbin/groupadd -f www
#/usr/sbin/useradd -g www www
会出现 nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied) 错误
原因:Linux只有root⽤户可以使⽤1024⼀下的端⼝
解决办法:1.已root权限启动
2.将 /usr/local/nginx/f ⽂件中的80端⼝改为1024以上
server {
# listen 80
listen8080
……
}
nginx: [alert] could not open error log file: open() “/usr/local/nginx/logs/error.log”failed (2: No such file or directory)
解决⽅法:
sudo chmod a+rwx -R logs
sudo chmod a+rwx -R /usr/local/nginx
发布评论