nginx編譯安裝

nginx 編譯安裝與配置使用
一、安裝編譯環境
yum -y install gcc gcc-c++
二、安裝pcre軟件包(使nginx支持http rewrite模塊)
yum install -y pcre pcre-devel
三、安裝openssl-devel(使nginx支持ssl)
yum install -y openssl openssl-devel
四、安裝zlib
yum install -y zlib zlib-devel
五、建立用戶nginx
useradd nginxhtml

passwd nginx nginx

六、安裝nginx
[root@localhost ~]# wget http://nginx.org/download/nginx-1.16.0.tar.gzc++

[root@localhost ~]# tar xzf nginx-1.16.0.tar.gz -C /usr/local/ 服務器

[root@localhost ~]# cd /usr/local/nginx-1.16.0/ 併發

[root@localhost nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --group=nginx -user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf -error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --httpclient-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --httpfastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lockpath=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --withhttp_gzip_static_module --with-pcre --with-http_realip_module --with-stream app

[root@localhost nginx-1.16.0]# make && make install

七、修改配置文件/etc/nginx/nginx.conf函數

# 全局參數設置 網站

user nginx; #指定用戶 編碼

worker_processes 4; #設置nginx啓動進程的數量,通常設置成與邏輯cpu數量相同 日誌

error_log logs/error.log; #指定錯誤日誌

worker_rlimit_nofile 10240; #設置一個nginx進程能打開的大文件數
pid /var/run/nginx.pid; events { worker_connections 1024; #設置一個進程的大併發鏈接數 }

# http 服務相關設置 http {

include mime.types;

default_type application/octet-stream; l

og_format main 'remote_addr - remote_user [time_local] "request" '

'status body_bytes_sent "$http_referer" ' '

"http_user_agent" "http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;                            #設置訪問日誌的位置和格式

sendfile on;                                                                          #是否調用sendfile函數輸出文件,通常設置爲on,若nginx是用來進行磁盤IO負載應用 時,能夠設置爲off,下降系統負載

gzip on;                                                                               #是否開啓gzip壓縮,將註釋去掉開啓

keepalive_timeout 65;                                                      #設置長鏈接的超時時間

# 虛擬服務器的相關設置

server { listen 80;                                                             #設置監聽的端口

server_name localhost;                                                  #設置綁定的主機名、域名或ip地址

# charset koi8-r;                                                              # 設置編碼字符

charset utf-8;

location / {

root /var/www/nginx;                                                     #設置服務器默認網站的根目錄位置,須要手動建立

index index.html index.htm;                                            #設置默認打開的文檔

}

error_page 500 502 503 504 /50x.html;                         #設置錯誤信息返回頁面

location = /50x.html {

root html;                                                                      #這裏的絕對位置是/usr/local/nginx/html

}

}

nginx.conf的組成:nginx.conf一共由三部分組成,分別爲:全局塊、events塊、http塊。在http塊中又包含http全局 塊、多個server塊。每一個server塊中又包含server全局塊以及多個location塊。在統一配置塊中嵌套的配置快,各個之間 不存在次序關係。
檢測nginx配置文件是否正確
[root@localhost ~]# /usr/local/nginx/sbin/nginx -t 

[root@localhost ~]# mkdir -p /tmp/nginx

[root@localhost ~]# mkdir /usr/local/nginx/logs 十、啓動nginx服務[root@localhost ~]# /usr/local/nginx/sbin/nginx

相關文章
相關標籤/搜索