Ubuntu 編譯安裝 nginx


--- title: Ubuntu 編譯安裝 nginx date: 2019/11/01 20:02 categories: tags: - Ubuntu - Linux - nginx - config ---
> 本人的有關博客:《[Windows 編譯安裝 nginx 服務器 + rtmp 模塊](https:////www.cnblogs.com/schips/p/12309174.html)》、《[Ubuntu 編譯安裝 nginx](https:////www.cnblogs.com/schips/p/12309201.html)》、《[Arm-Linux 移植 Nginx](https:////www.cnblogs.com/schips/p/12308651.html)》

准備

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;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM