#安装PCRE库支持
yum install pcre-devel pcre -y
#下载Nginx源码包
cd /usr/src
wget -c http://nginx.org/download/nginx-1.12.0.tar.gz
#解压Nginx源码包
tar -xzf nginx-1.12.0.tar.gz
#进入解压目录,然后sed修改Nginx版本信息为JWS
cd nginx-1.12.0 ; sed -i -e ‘s/1.12.0//g’ -e ‘s/nginx//JWS/g’ -e
‘s/”NGINX”/”JWS”/g’ src/core/nginx.h
#预编译Nginx
useradd www ;./configure –user=www –group=www –prefix=/usr/local/nginx –with-http_stub_status_module –with-http_ssl_module
#.configure预编译成功后,执行make命令进行编译
make
#make执行成功后,执行make install 正式安装
make install
#至此Nginx WEB服务器安装完毕。
/usr/local/nginx/sbin/nginx -t 检查nginx配置文件是否正确
然后启动nginx,/usr/local/nginx/sbin/nginx 回车即可。查看进程是否已启动:
[root@localhost ~]# ps -ef |grep nginx
nobody 5381 30285 0 May16 ? 09:04:31 nginx: worker process
root 30285 1 0 2017 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
root 32260 32220 0 12:34 pts/0 00:00:00 grep nginx
[root@localhost ~]#
#中间碰见问题:nginx进程正常但,无法正常打开网页,通过百度修改nginx.conf文件里的user nobody 行,把前面的井号去掉,运行正常。
user nobody格式: user user [group
user : 指定nginx 运行的用户
group: 指定nginx可运行的组
本地浏览器输入linux网卡地址即可访问主页:
welcome to nginx
#相关查询命令:
nginx -s reload 重启服务
nginx -t 检查nginx配置文件是否正常
#配置本地电脑host文件
文件路径:C:WindowsSystem32driversetc在host文件的空白处添加个nginx主机的ip和域名对应关系
192.168.88.71 www.fjtest.net
192.168.88.71 www.fjtest2.net
#编辑nginx.conf文件
vim /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;
server_name www.fjtest.net;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/fj;
index index.html index.htm;
}
}
server {
listen 80;
server_name www.fjtest2.net;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html/fj2;
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;
}
#同时创建了html下的两个文件,一个叫fj,一个叫fj2,然后把html下的index.html文件拷贝到对应的文件内。
ca
#完成后即可通过浏览器分别访问两个域名:www.fjtest.net和www.fjtest.net