FreeBSD 使用 Nginx 的 pkg 时的注意事项 基础篇.
这是关于在FreeBSD上使用Nginx的pkg的备忘录。基本部分。
与Nginx相关的pkg列表
# pkg search nginx
nginx-1.14.2,2 Robust and small WWW server
nginx-devel-1.15.7_2 Robust and small WWW server
nginx-full-1.14.2,2 Robust and small WWW server (full package)
nginx-lite-1.14.2,2 Robust and small WWW server (lite package)
nginx-naxsi-1.14.2,2 Robust and small WWW server (plus NAXSI)
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.26 Testing modules for Nginx C module development
py27-certbot-nginx-0.29.1 NGINX plugin for Certbot
py36-certbot-nginx-0.29.1 NGINX plugin for Certbot
rubygem-passenger-nginx-6.0.0 Modules for running Ruby on Rails and Rack applications
只需要给出一种翻译:
我们忽略掉p5(perl)、py(python)和rubygem(ruby),然后解释其他的软件包。
nginx
中文: Nginx
稳定的Nginx版本。截至2018年12月10日,版本为1.14.2。通过-V选项可以查看构建时的选项,确认如下。
# nginx -V
nginx version: nginx/1.14.2
built with OpenSSL 1.0.2o-freebsd 27 Mar 2018
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
nginx开发版
Nginx的主版本是”mainline版”。截至2018年12月10日,版本号为1.15.7。
构建选项与nginx软件包相同吧。
# nginx -V
nginx version: nginx/1.15.7
built with OpenSSL 1.0.2o-freebsd 27 Mar 2018
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
nginx全套
这是一个启用了所有在ports中指定的选项的稳定版Nginx版本。如果你想要使用某个模块,只需安装并使用这个版本即可。由于安装过程中可能会安装许多包,因此我并没有进行安装。
nginx-lite 即轻量级的 nginx。
稳定版的Nginx,构建选项较少。
# nginx -V
nginx version: nginx/1.14.2
built with OpenSSL 1.0.2o-freebsd 27 Mar 2018
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 --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_realip_module --with-pcre --with-http_ssl_module --without-mail_imap_module --without-mail_pop3_module --without-mail_smtp_module --with-threads
nginx-naxsi 是一个网络服务器软件。
带有WAF(Web应用程序防火墙)的稳定版Nginx,已经编译好的Nginx。
# nginx -V
nginx version: nginx/1.14.2
built with OpenSSL 1.0.2o-freebsd 27 Mar 2018
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-threads --with-mail=dynamic --with-stream=dynamic --add-dynamic-module=/wrkdirs/usr/ports/www/nginx-naxsi/work/naxsi-0.56/naxsi_src
确认已安装的文件
如果是nginx软件包的情况。
# pkg info -l nginx
nginx-1.14.2,2:
/usr/local/etc/nginx/fastcgi_params-dist
/usr/local/etc/nginx/koi-utf
/usr/local/etc/nginx/koi-win
/usr/local/etc/nginx/mime.types-dist
/usr/local/etc/nginx/nginx.conf-dist
/usr/local/etc/nginx/scgi_params-dist
/usr/local/etc/nginx/uwsgi_params-dist
/usr/local/etc/nginx/win-utf
/usr/local/etc/rc.d/nginx
/usr/local/libexec/nginx/ngx_mail_module.so
/usr/local/libexec/nginx/ngx_stream_module.so
/usr/local/man/man8/nginx.8.gz
/usr/local/sbin/nginx
/usr/local/share/licenses/nginx-1.14.2,2/BSD2CLAUSE
/usr/local/share/licenses/nginx-1.14.2,2/LICENSE
/usr/local/share/licenses/nginx-1.14.2,2/catalog.mk
/usr/local/share/vim/vimfiles/ftdetect/nginx.vim
/usr/local/share/vim/vimfiles/ftplugin/nginx.vim
/usr/local/share/vim/vimfiles/indent/nginx.vim
/usr/local/share/vim/vimfiles/syntax/nginx.vim
/usr/local/www/nginx-dist/50x.html
/usr/local/www/nginx-dist/EXAMPLE_DIRECTORY-DONT_ADD_OR_TOUCH_ANYTHING
/usr/local/www/nginx-dist/index.html
Nginx的配置和启动方法
設定文件的路径
/usr/local/etc/nginx/nginx.conf
配置使Nginx可用(在操作系统启动时启动Nginx)
# sysrc nginx_enable="YES"
如果想试着启动而不进行以上设置,您可以使用以下命令进行启动。
# /usr/local/etc/rc.d/nginx onestart
启动Nginx的命令
# /usr/local/etc/rc.d/nginx start
または
# service nginx start
停止Nginx的命令
# /usr/local/etc/rc.d/nginx stop
または
# service nginx stop
重启Nginx的命令
# /usr/local/etc/rc.d/nginx restart
または
# service nginx restart
用于更新Nginx配置文件的命令,例如当你更新Nginx配置文件时使用。
# /usr/local/etc/rc.d/nginx reload
または
# service nginx reload
检查Nginx配置文件的命令。
# /usr/local/etc/rc.d/nginx configtest
または
# service nginx configtest
当更新Nginx时,执行的命令是什么?
# /usr/local/etc/rc.d/nginx upgrade
または
# service nginx upgrade
Nginx 优雅停机
# /usr/local/etc/rc.d/nginx gracefulstop
または
# service nginx gracefulstop
使用dynamic模块时的注意事项。
在设置文件(/usr/local/etc/nginx/nginx.conf)中添加load_module。
由于nginx包中的mail模块和stream模块是动态的,
所以如果需要使用它们,需要添加以下设置。
load_module /usr/local/libexec/nginx/ngx_mail_module.so;
load_module /usr/local/libexec/nginx/ngx_stream_module.so;