Ubuntu安装nginx

我用的是Ubuntu 16.04安装nginx。

1.输入:
apt-get install build-essential
apt-get install libtool

2.安装pcre依赖库(http://www.pcre.org/)
sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev

3.安装zlib依赖库(http://www.zlib.net)
apt-get install zlib1g-dev

4.安装ssl依赖库
apt-get install openssl

5.安装nginx(http://nginx.org)
#下载最新版本:
wget http://nginx.org/download/nginx-1.11.3.tar.gz
#解压:
tar /root nginx-1.11.3.tar.gz
#进入解压目录:
cd /root nginx-1.11.3
#配置:
./configure --prefix=/usr/local/nginx
#编辑nginx:
make
注意:这里可能会报错,提示“pcre.h No such file or directory”,具体详见:http://stackoverflow.com/questions/22555561/error-building-fatal-error-pcre-h-no-such-file-or-directory
需要安装 libpcre3-dev,命令为:sudo apt-get install libpcre3-dev
#安装nginx:
sudo make instal

#启动nginx:
sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
注意:-c 指定配置文件的路径,不加的话,nginx会自动加载默认路径的配置文件,可以通过 -h查看帮助命令。
注意:如果启动失败,输入“netstat -ntpl”查看网络进程,看端口是否被占用。比如如果80端口被占用,输入“kill 进程编号”强制关闭进程在输入“/usr/local/nginx/sbin/nginx”启动nginx。
#查看nginx进程:
ps -ef|grep nginx

6.nginx常用命令
启动:
/usr/local/nginx/sbin/nginx
停止:
/usr/local/nginx/sbin/nginx -s stop
重新加载配置:
/usr/local/nginx/sbin/nginx -s reload
指定配置文件:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
查看版本:
/usr/local/nginx/sbin/nginx -v
查看帮助信息:
/usr/local/nginx/sbin/nginx -h
检查配置文件是否正确:
/usr/local/nginx/sbin/nginx -t

7.配置nginx.conf
server {
listen 80;
#网站域名
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
#网站根目录
root /home/web/www;
index index.html index.htm;
}

#error_page 404 /404.html;
注意:这里有个巨坑!访问网站报403的错误,是权限的问题,一定不能设置777。这里我设置755就可以了:
chmod -R 755 /home/web/www
-R表示递归

时间: 2024-08-10 19:15:51

Ubuntu安装nginx的相关文章

Ubuntu 安装nginx

1.更新Ubuntu # add-apt-repository 仓库名称 # apt-get update # apt-get install -y libssl1.0.2 openssl 2.安装Nginx # apt-get install -y nginx # apt-get install -y nginx-extras 3.设置Nginx通用配置文件 cat /etc/nginx/nginx.conf user www-data; #ubuntu里面nginx用户名 worker_pr

ubuntu安装nginx pagespeed

一.自动安装 使用最新稳定版本的ngx_pagespeed自动安装依赖项并构建最新的主线版nginx,请运行: $ sudo bash <(curl -f -L -sS https://ngxpagespeed.com/install) --nginx-version latest 二.手动安装 1.安装依赖 $ sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip uuid-dev libxslt

ubuntu安装nginx配置反向代理服务器

安装nginx: sudo apt-get install nginx 启动nginx; sudo service nginx start 如果报了这样的错误: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)2015/01/16 15:55:46 [warn] 1973#0: the "user" direc

Ubuntu安装nginx(复制)

gcc.g++依赖库 apt-get install build-essential apt-get install libtool 安装 pcre依赖库(http://www.pcre.org/) sudo apt-get install libpcre3 libpcre3-dev 或源码安装: cd /usr/local/src wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz tar -z

Ubuntu 安装 nginx

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-09/147157.htm 1.安装依赖项 sudo apt-get update sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev libxml2-dev libgd2-xpm-dev libgeoip-dev libgoogle-perftools-dev libp

ubuntu 安装nginx redis dotnet

1 安装nginx sudo apt-get update sudo apt-get install nginx 配置文件 /etc/nginx/nginx.conf 2 安装redis sudo add-apt-repository universe sudo apt-get update sudo apt-get install redis-server 配置文件 vim /etc/redis/redis.conf 3 安装dotnet 1)在线包管理器安装 参考:https://docs.

Ubuntu安装 Nginx

一 Ubuntu(Debian)软件包安装 apt-get update apt-get install nginx Ubuntu10.04安装openssl,执行如下操作来安装openssl及其开发函数库: sudo apt-get install openssl sudo apt-get install libssl0.9.8 sudo apt-get install libssl-dev PCRE库安装 sudo apt-get update sudo apt-get install li

ubuntu安装nginx与配置

命令行安装:(当前时间为2018.11,版本为1.10.3) sudo apt-get install nginx 安装好的文件位置: /usr/sbin/nginx:主程序 /etc/nginx:存放配置文件 /usr/share/nginx:存放静态文件 /var/log/nginx:存放日志 查找Nginx启动文件路径 find / -name nginx.conf 查询nginx进程 ps -ef | grep nginx 重启nginx sudo nginx -s reload 查看是

ubuntu安装nginx时提示error: the HTTP rewrite module requires the PCRE library

需要安装pcre包. sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev 你可能还需要安装 sudo apt-get install openssl libssl-dev