sudo tar -zxvf nginx-xxx.tar.gz
sudo apt-get install gcc zlib1g-dev libpcre3 libpcre3-dev openssl libssl-dev
./configure & make & make install
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
複製代碼
vim /etc/yum.repos.d/nginx.repo
html
yum install nginx -y
nginx
[root@centos ~]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.14.2
/usr/share/doc/nginx-1.14.2/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx
複製代碼
路徑 | 類型 | 做用 |
---|---|---|
/etc/logrotate.d/nginx | 配置文件 | Nginx 日誌輪轉,用於 logrotate 服務的日誌切割 |
/etc/nginx/nginx.conf /etc/nginx/conf.d/default.conf |
目錄 | Nginx 主配置文件 |
/etc/nginx/fastcgi_params | 配置文件 | fastcgi 配置 |
/etc/nginx/uwsgi_params | 配置文件 | uwsgi 配置 |
/etc/nginx/scgi_params | 配置文件 | cgi 配置 |
/etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf |
配置文件 | 編碼轉換映射轉化文件 |
/etc/nginx/mime.types | 配置文件 | 設置 http 協議的 Content-Type 與擴展名對應關係 |
/usr/lib/systemd/system/nginx-debug.service /usr/lib/systemd/system/nginx.service /etc/sysconfig/nginx /etc/sysconfig/nginx-debug |
配置文件 | 用於配置出系統守護進程管理器管理方式 |
/usr/lig64/nginx/modules /usr/nginx/modules |
目錄 | Nginx 模塊目錄 |
/usr/sbin/nginx/ /usr/sbin/nginx-debug |
命令 | Nginx 服務的啓動管理的終端命令 |
/var/cache/nginx | 目錄 | Nginx 的緩存目錄 |
/var/log/nginx | 目錄 | Nginx 的日誌目錄 |
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
複製代碼
參數 | 做用 |
---|---|
user | 設置 nginx 服務的系統使用用戶 |
worker_processes | 工做進程數(和 cpu 核心數保持一致就好了) |
error_log | nginx 錯誤日誌 |
pid | nginx 服務啓動的 pid |
events 參數 | 做用 |
---|---|
use | 工做進程數 |
worker_connections | 每一個進程容許最大鏈接數 |
http { //http 的服務配置
...
include mime.types;
default_type application/octet-stream;
// log 輸出格式配置
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
// 超時時間配置 單位是秒
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server { //每個 server 站點配置
listen 8080; //監聽端口
server_name localhost; //主機名、域名
location / { //控制訪問路徑 這裏配置的是 / 路徑
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html; // 錯誤頁面
location = /50x.html { // 錯誤頁面的路徑
root html;
}
}
server {
... ...
}
}
複製代碼
http
模塊: http 的服務配置vim
server
模塊: 每個 server
站點配置centos
listen
: 監聽端口緩存
server_name
: 主機名、域名bash
location
模塊 : 控制訪問路徑app
error_page
: 配置錯誤頁面tcp
nginx -t -c /usr/local/etc/nginx/nginx.conf
複製代碼
-t
是檢查配置是否正確ui
-c
是指定路徑編碼