--- title: Ubuntu 编译安装 nginx date: 2019/11/01 20:02 categories: tags: - Ubuntu - Linux - nginx - config ---

> 本人的有关博客:《[Windows 编译安装 nginx 服务器 + rtmp 模块]()》、《[Ubuntu 编译安装 nginx]()》、《[Arm-Linux 移植 Nginx]()》

准备

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 libperl-dev libtool libpcrecpp0v5 openssl -y

2、下载nginx

wget http://nginx.org/download/nginx-1.13.5.tar.gz && tar -xf nginx-1.13.5.tar.gz

编译安装

进入解压目录:cd nginx-1.13.5

配置:这里额外安装几个模块

./configure --sbin-path=/usr/local/nginx/nginx \

--prefix=/usr/local/nginx \

--conf-path=/usr/local/nginx/nginx.conf \

--pid-path=/usr/local/nginx/nginx.pid \

--add-module=../nginx-rtmp-module-master \

--with-http_ssl_module \

--with-stream --with-mail=dynamic

编辑安装nginx:

sudo make && sudo make install

启动nginx

sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

注意:-c 指定配置文件的路径,不加的话,nginx会自动加载默认路径的配置文件,可以通过 -h查看帮助命令。

查看nginx进程:

ps -ef | grep nginx

建立软链接(由于/usr/local/bin包含于$PATH当中,这样就不需要额外的设置环境变量了,这意味着可以在其他路径下直接运行nginx命令)

sudo ln -s /opt/dotnet/dotnet /usr/local/bin #(创建链接)

附录

编译选项说明:

--prefix=path 如果在编译的不指定安装位置,那么默认的位置/usr/local/nginx目录

--sbin-path=path 设置nginx执行脚本的位置,默认位置${prefix}/sbin/nginx 注意这里的prefix是在配置文件里面配置的路径

--conf-path=path 配置nginx配置文件的路径,如果不指定这个选项,那么配置文件的默认路径就会是 ${prefix}/conf/nginx.conf

--pid-path =path 配置nginx.pid file的路径,一般来说,进程在运行的时候的时候有一个进程id,这个id会保存在pid file里面,默认的pid file的放置位置是prefix/logs/nginx.pid

--error-log-path=path 设置错误日志的存放路径,默认${prefix}/logs/error.log

--http-log-path= path 设置http访问日志的路径,就默认${prefix}/logs/access.log

--user=name 设置默认启动进程的用户,如果不指定,就默认 nobody

--group=name 设置这个用户所在的用户组,如果不指定,依然是nobody

--with-http_ssl_module 开启HTTP SSL模块,使NGINX可以支持HTTPS请求。需要安装OPENSSL

--with-http_flv_module

--with-http_stub_status_module 启用 "server status" 页

--without-http_gzip_module 禁用 ngx_http_gzip_module. 如果启用,需要 zlib

--without-http_ssi_module 禁用 ngx_http_ssi_module

--without-http_referer_module 禁用 ngx_http_referer_module

--without-http_rewrite_module 禁用 ngx_http_rewrite_module. 如果启用需要 PCRE 。

--without-http_proxy_module 禁用 ngx_http_proxy_module

--without-http_fastcgi_module 禁用 ngx_http_fastcgi_module

--without-http_memcached_module 禁用 ngx_http_memcached_module

--without-http_browser_module 禁用 ngx_http_browser_module

--http-proxy-temp-path=PATH 设置路径到the http proxy temporary files

--http-fastcgi-temp-path=PATH 设置路径到Set path to the http fastcgi temporary files

--without-http 禁用 HTTP server

--with-mail 启用 IMAP4/POP3/SMTP 代理模块

--with-mail_ssl_module 启用ngx_mail_ssl_module

--with-openssl=DIR 设置路径到OpenSSL library sources

--with-stream 用来实现四层协议的转发、代理或者负载均衡等

测试 nginx

在浏览器中输入 带有运行nginx服务的机子的 IP地址,端口号要参考 conf文件 中 listen 的端口号

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
}

如果说我的文章对你有用,只不过是我站在巨人的肩膀上再继续努力罢了。