FreeBSD 11.3安装Nginx 1.18小记
原文地址:FreeBSD 11.3安装Nginx 1.18小记
本篇文章记录了在阿里云的FreeBSD 11.3中安装nginx 1.18的全部过程以及介绍了如何注册nginx为系统服务在开机时启动、停止nginx、重载nginx配置文件。
今天试着在阿里云上折腾了一把FreeBSD系统,刚开始很不习惯,结果装完nginx之后感觉有点喜欢FreeBSD。因为我发现FreeBSD安装软件并么有想象中的那么难,软件也没有想象中的那么旧。例如这次安装的nginx一看竟然是1.18版本的,而你如果使用debian和centos安装的话就有点折腾了。
目前阿里云的FreeBSD系统最高支持到11.3。本篇文章记录一下如何在FreeBSD 11.3上安装nginx 1.18。
1.更新FreeBSD的仓库(ports)
输入下面的命令即可更新仓库,更新仓库源之后有很多软件的新版本,同时也保留旧版本。
portsnap fetch update
提示:更新如果很慢的话可以更改一下FreeBSD的源,可以直接在本站搜索“FreeBSD更换仓库源”。网上很多人说FreeBSD的仓库源只能用官方的,其实不然。
2.直接使用pkg命令安装nginx
在使用pkg安装nginx之前可以搜索一下有哪些nginx版本可以安装,运行以下命令:
pkg search nginx
输出:
modsecurity3-nginx-1.0.1_1 Instruction detection and prevention engine / nginx Wrapper
nginx-1.18.0_25,2 Robust and small WWW server
nginx-devel-1.19.3_3 Robust and small WWW server
nginx-full-1.18.0_5,2 Robust and small WWW server (full package)
nginx-lite-1.18.0_25,2 Robust and small WWW server (lite package)
nginx-naxsi-1.18.0_25,2 Robust and small WWW server (plus NAXSI)
nginx-prometheus-exporter-0.8.0 Prometheus exporter for NGINX and NGINX Plus stats
nginx-ultimate-bad-bot-blocker-4.2020.03.2005_1 Nginx bad bot and other things blocker
nginx-vts-exporter-0.10.3 Server that scraps NGINX vts stats and export them via HTTP
p5-Nginx-ReadBody-0.07_1 Nginx embeded perl module to read and evaluate a request body
p5-Nginx-Simple-0.07_1 Perl 5 module for easy to use interface for Nginx Perl Module
p5-Test-Nginx-0.28 Testing modules for Nginx C module development
py27-certbot-nginx-1.8.0 NGINX plugin for Certbot
py37-certbot-nginx-1.8.0 NGINX plugin for Certbot
rubygem-passenger-nginx-6.0.6 Modules for running Ruby on Rails and Rack applications
看来只有1.18版本的。然后运行install命令安装nginx。
pkg install nginx
3.检查nginx是否安装成功
nginx -V
输出:
nginx version: nginx/1.18.0
built with OpenSSL 1.0.2u-freebsd 20 Dec 2019 (running with OpenSSL 1.0.2s-freebsd 28 May 2019)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/etc/nginx --with-cc-opt='-I /usr/local/include' --with-ld-opt='-L /usr/local/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --sbin-path=/usr/local/sbin/nginx --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --user=www --group=www --modules-path=/usr/local/libexec/nginx --with-file-aio --http-client-body-temp-path=/var/tmp/nginx/client_body_temp --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp --http-proxy-temp-path=/var/tmp/nginx/proxy_temp --http-scgi-temp-path=/var/tmp/nginx/scgi_temp --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp --http-log-path=/var/log/nginx/access.log --with-http_v2_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-pcre --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module --with-mail_ssl_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-mail=dynamic --with-stream=dynamic
4.注册nginx为系统服务,使用service命令管理nginx
在linux系统中,某些软件直接会注册为系统服务。FreeBSD使用如下命令注册系统服务。注册为系统服务之后就可以使用service来管理nginx。命令如下:
echo 'nginx_enable="YES"' >> /etc/rc.conf
或者
sysrc nginx_enable="YES"
运行完以上命令之后可以使用cat /etc/rc.conf查看一下rc.conf里是否增加了nginx服务。nginx_enable="YES"出现在rc.conf中。(注:rc.conf规定了哪些应用在系统引导时启动)
root@iZuf6ex1vq9wpu4qyuu2:~ # cat /etc/rc.conf
hostname="AlibabaCloud"
sshd_enable="YES"
dumpdev="NO"
ip6addrctl_enable="NO"
ip6addrctl_policy="ipv4_prefer"
ipv6_activate_all_interfaces="NO"
ipv6_network_interfaces="none"
ifconfig_lo0="inet 127.0.0.1 netmask 255.0.0.0"
ifconfig_vtnet0="inet 172.19.55.205 netmask 255.255.240.0"
defaultrouter="172.19.63.253"
hostname="iZuf6ex1vq9wpu4qyuu"
nginx_enable="YES"
5.启动nginx服务器
service nginx start
如果没有报错说明nginx正常启动,可以使用如下命令检测一下nginx的状态。
service nginx status
输出一下内容,证明nginx启动正常。
nginx is running as pid 88308.
6.nginx的配置文件路径、以及重启,停止nginx
FreeBSD的nginx的配置文件路径如下:
/usr/local/etc/nginx/nginx.conf
FreeBSD重启nginx
service nginx restart
FreeBSD重载配置文件
service nginx reload
FreeBSD停止服务
service nginx stop
好了,以上就是关于在FreeBSD 11.3上安装nginx 1.18的全部过程。
{{ nComment.author.nickname }}
{{ nComment.time }}