準備服務器
centos7.2html
確保有網絡linux
ping www.baidu.com
確保yum可用nginx
yum list | grep gcc
關閉iptables規則c++
# 查看iptables規則 iptables -L # 關閉iptables規則 iptables -F # 保險起見,再查看下查nat表裏是否有規則 iptables -t nat -L # 有的話,也關閉 iptables -t nat -F
關閉selinux策略centos
# 查看selinux是否開啓 getenforce # 關閉 setenforce 0
安裝基礎庫緩存
yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake
訪問Nginx官網
http://nginx.org/en/linux_pac...服務器
複製如下yum源網絡
[nginx] name=nginx repo baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/ gpgcheck=0 enabled=1
服務器上建立nginx的yum源app
cd /etc/yum.repos.d vi nginx.repo
# OS/OSRELEASE改爲centos/7 [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1
驗證yum源dom
yum list | grep nginx ... nginx.x86_64 1:1.12.2-1.el7_4.ngx nginx ...
從yum源安裝nginx
yum install nginx
驗證nginx
nginx -v # 顯示以下 nginx version: nginx/1.12.2
啓動Nginx
systemctl start nginx.service
進程確認
ps -aux | grep nginx
root 9384 0.0 0.0 46296 952 ? Ss 22:30 0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf nginx 9386 0.0 0.1 46680 1912 ? S 22:30 0:00 nginx: worker process root 9388 0.0 0.0 112648 968 pts/0 R+ 22:30 0:00 grep --color=auto nginx
訪問一下,80默認端口
初始備用目錄
cd /opt mkdir app download logs work backup
備份Nginx配置文件
cp /etc/nginx/nginx.conf /opt/backup cp /etc/nginx/conf.d/default.conf /opt/backup
查看安裝過程都建立了哪些文件/目錄
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.12.2 /usr/share/doc/nginx-1.12.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 /etc/nginx/nginx.conf /etc/nginx/conf.d /etc/nginx/conf.d/default.conf |
目錄、配置文件 | Nginx主配置文件 |
/etc/nginx/fastcgi_params /etc/nginx/uwsgi_params /etc/nginx/scgi_params |
配置文件 | cgi配置相關,fastcgi配置 |
/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 |
配置文件 | (centos7)配置出系統守護進程管理器的管理方式 |
/usr/lib64/nginx/modules /etc/nginx/modules |
目錄 | nginx模塊目錄 |
/usr/sbin/nginx /usr/sbin/nginx-debug |
命令 | nginx服務的啓動終端管理命令 |
/var/cache/nginx | 目錄 | Nginx的緩存目錄 |
/var/log/nginx | 目錄 | nginx的日誌目錄 |
查看安裝過程的編譯參數
nginx -V
nginx version: nginx/1.12.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips 26 Jan 2017 TLS SNI support enabled configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --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-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
相關編譯參數的說明
編譯選項 | 做用 |
---|---|
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock |
安裝目的目錄或路徑 |
--http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp |
執行對應模塊時nginx所保留的臨時文件 |
--user=nginx --group=nginx |
設定Nginx進程啓動的用戶和用戶組 |
--with-cc-opt=parameters | 設置額外的參數將被添加到CFLAGS變量 |
--with-ld-opt=parameters | 設置附加參數,連接系統庫 |
--with-http_sub_status_module | Nginx客戶端狀態 |
--with-http_random_index_module | 目錄中隨機選擇一個隨機主頁 |
--with-http_sub_module | HTTP內容替換 |