ubuntu下编译安装nginx

加载依赖包:

sudo apt-get update

sudo apt-get install libxml2-dev

sudo apt-get install build-essential

sudo apt-get install openssl

sudo apt-get install libssl-dev

sudo apt-get install make

sudo apt-get install curl

sudo apt-get install libcurl4-gnutls-dev

sudo apt-get install libjpeg-dev

sudo apt-get install libpng-dev

sudo apt-get install libtool-bin

sudo apt-get install bison

sudo apt-get install zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev  libgeoip-dev libgoogle-perftools-dev libperl-dev libtool

sudo apt-get install libxml2-dev build-essential openssl  libssl-dev make curl  libcurl4-gnutls-dev libjpeg-dev  libpng-dev libtool-bin bison  zlib1g-dev libpcre3 libpcre3-dev libssl-dev libxslt1-dev  libgeoip-dev libgoogle-perftools-dev libperl-dev libtool 

 


编译安装nginx:

1、下载新版本,到官网复制下载链接

wget http://nginx.org/download/nginx-1.17.4.tar.gz

2、解压tar -zxvf nginx-1.17.4.tar.gz

3、编译安装

# 进入解压目录:

cd nginx-1.17.4.tar.gz

# 配置并编译安装nginx:

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-stream --with-mail=dynamic

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执行脚本的位置,这里如果设置在path变量里面,就可以在bash环境下,任意使用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自启动,在/lib/systemd/system/ 目录下创建一个服务文件

vim /lib/systemd/system/nginx.service

内容如下:

[Unit]

Description=nginx - high performance web server

After=network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]

WantedBy=multi-user.target

文件说明

[Unit]部分

Description:描述服务

After:依赖,当依赖的服务启动之后再启动自定义的服务

[Service]部分

Type=forking是后台运行的形式

ExecStart为服务的具体运行命令(需要根据路径适配)

ExecReload为重启命令(需要根据路径适配)

ExecStop为停止命令(需要根据路径适配)

PrivateTmp=True表示给服务分配独立的临时空间

注意:启动、重启、停止命令全部要求使用绝对路径

[Install]部分

服务安装的相关设置,可设置为多用户

# 设置了自启动后,任意目录下执行

systemctl enable nginx.service

# 启动nginx服务

systemctl start nginx.service

# 设置开机自动启动

systemctl enable nginx.service

# 停止开机自动启动

systemctl disable nginx.service

# 查看状态

systemctl status nginx.service

# 重启服务

systemctl restart nginx.service

# 查看所有服务

systemctl list-units --type=service

 

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Ubuntu上进行源码编译安装Nginx,你可以按照以下步骤进行操作: 1. 首先,确保你的系统已经更新并安装了必要的依赖项。你可以使用以下命令来更新系统并安装构建所需的工具和库: \[2\] ``` sudo apt-get update sudo apt-get install build-essential sudo apt-get install libtool sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install zlib1g-dev sudo apt-get install libssl-dev ``` 2. 下载Nginx的压缩包,并解压缩: \[2\] ``` # 假设你已经下载了Nginx的压缩包,并将其放在当前目录下 tar -zxvf nginx-x.x.x.tar.gz cd nginx-x.x.x ``` 3. 执行configure命令来配置编译选项和安装路径: \[1\] ``` ./configure --prefix=/usr/local/nginx \ --user=nginx --group=nginx \ --with-http_gzip_static_module \ --with-http_flv_module \ --with-http_ssl_module \ --with-http_realip_module \ --with-http_v2_module \ --with-http_sub_module \ --with-http_mp4_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-pcre --with-stream \ --with-stream_ssl_module \ --with-stream_realip_module ``` 这个命令将根据你的需求配置Nginx,并指定安装路径为`/usr/local/nginx`。 4. 执行make命令来编译Nginx: \[1\] ``` make ``` 5. 执行make install命令来安装Nginx: \[1\] ``` make install ``` 这将把编译好的Nginx安装到指定的安装路径。 完成以上步骤后,你就成功地在Ubuntu上通过源码编译安装Nginx。你可以根据需要进行进一步的配置和使用。 #### 引用[.reference_title] - *1* *2* [【UbuntuUbuntu编译安装Nginx](https://blog.csdn.net/weixin_43712023/article/details/123829187)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值