1、安裝依賴包
# yum -y install gcc openssl-devel pcre-devel httpd-tools gcc-c++ wget vim tree
2、下載nginx
# wget http://nginx.org/download/nginx-1.10.2.tar.gz
3、解壓nginx
# tar xf nginx-1.10.2.tar.gz
4、進入nginx目錄
# cd nginx-1.10.2/
5、創(chuàng)建nginx用戶
# useradd nginx
6、檢查配置文件
# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
如果安裝報錯:
./configure: error: the HTTP rewrite module requires the PCRE library.
# yum -y install pcre-devel openssl openssl-devel
7、編譯并安裝
# make && make install
8、建立快捷方式
# ln -s /usr/local/nginx/sbin/nginx /usr/sbin/
9、啟動nginx服務
# nginx
10、檢查nginx監(jiān)聽信息
# netstat -anptu | grep nginx
CentOS 7 命令變了:
# ss | grep nginx
11、修改配置
# vim /usr/local/nginx/conf/nginx.conf
# firewall-cmd --zone=public --add-port=80/tcp --permanent
# firewall-cmd --reload
配置內容
worker_processes 1;
events {
? worker_connections 65535;
}
http {
? include mime.types;
? default_type application/octet-stream;
? sendfile on;
? keepalive_timeout 65;
? server {
? listen 80;
? server_name localhost;
? location / {
? root html;
? index index.html index.htm;
? }
? error_page 500 502 503 504 /50x.html;
? location = /50x.html {
? root html;
? }
?? }
}
12、刷新配置
# nginx -s reload #重啟nginx,刷新配置