系統(tǒng)環(huán)境:Centos 7.0
1.下載相關(guān)包
- 安裝依賴包
> yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
- 創(chuàng)建存放nginx安裝包的文件夾
> mkdir /usr/local/nginx
- 進(jìn)入nginx文件夾
> cd /usr/local/nginx
- 下載nginx的tar包
> wget http://nginx.org/download/nginx-1.13.7.tar.gz
- 將解壓的tar包解壓至當(dāng)前文件夾
> tar -xvf nginx-1.13.7.tar.gz
3.安裝nginx
- 進(jìn)入解壓完的目錄
> cd nginx-1.13.7
- 生成makefile文件
> ./configure
- 編譯
> make
- 安裝
> make install
4.配置nginx.conf
> vi /usr/local/nginx/conf/nginx.conf # 編譯配置文件
#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;
}
http {
include mime.types;
default_type application/octet-stream;
#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 {
listen 80; # 修改這里 對(duì)應(yīng)的是端口號(hào)帜讲,默認(rèn)的端口是80
server_name localhost; # # 修改這里 對(duì)應(yīng)的是ip躏升,默認(rèn)的是本地的
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
"nginx.conf" 117L, 2664C
4.啟動(dòng)nginx服務(wù)
- 啟動(dòng)nginx服務(wù)
> /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
> /usr/local/nginx/sbin/nginx -s reload # 啟動(dòng)nginx服務(wù)
- 關(guān)閉防火墻
> systemctl stop firewalld.service
- 查看nginx進(jìn)程
> ps -ef | grep nginx
root 4460 1 0 19:30 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -
c /usr/local/nginx/conf/nginx.conf
nobody 5123 4460 0 19:33 ? 00:00:00 nginx: worker process
root 11075 11759 0 20:05 pts/0 00:00:00 vi nginx.conf
root 11529 11759 0 20:08 pts/0 00:00:00 vi //usr/local/nginx/conf
root 11654 11759 0 20:08 pts/0 00:00:00 vi nginx.conf
root 13807 11759 0 20:20 pts/0 00:00:00 grep --color=auto nginx
-
服務(wù)啟動(dòng)成功后 在網(wǎng)頁(yè)中輸入ip地址和端口 如果成功則出現(xiàn)下方展示頁(yè)
nginx 服務(wù)配置成功后 一些常規(guī)操作
> cd /usr/local/nginx/sbin # 進(jìn)入此文件夾
> ./nginx # 啟動(dòng)nginx服務(wù)
> ./nginx -s stop # 關(guān)閉nginx服務(wù)
> ./nginx -s reload # 重啟nginx服務(wù)