Nginx安装

Nginx安装:
方式1. yum安装
配置nginx的yum源,而后用yum install -y nginx来安装html

方式2. 源码安装
#1. 中止原有web服务器nginx

#2. 添加普通用户帐号来运行nginx:
useradd nginx -M -r -s /sbin/nologinweb

#2.1 安装依赖包
yum install -y gcc pcre-devel openssl-devel服务器

#3. 解压并安装Nginx:
wget + nginx官网本身想要的nginx版本连接(我选的的是nginx-1.10.3.版本)
tar xvf nginx-1.10.3.tar.gz
cd nginx-1.10.3
./configure --user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_modulecurl

make && make installtcp

#3.1 建立软连接文件
ln -s /usr/local/nginx/sbin/nginx /sbin/nginx
#显示nginx命令帮助信息
nginx -hide

#4. 启动:
#检测配置文件语法
nginx -t
#启动nginx服务
nginx测试

查看命令帮助:
/usr/local/nginx/sbin/nginx  -h
-v      查看nginx版本
-V      查看编译参数 
-t      测试默认配置文件
-c      加载非默认位置配置文件
-s     指定操做信号,如restart、reload、stop、quit等。
如nginx   -s  stop中止nginx服务
  1. 查看启动状态:
    # ps aux | grep nginx
    root 8416 0.0 0.1 5760 660 ? Ss 23:29 0:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    nginx 8417 0.0 0.1 5904 992 ? S 23:29 0:00 nginx: worker process网站

    # netstat -ntlp | grep 80
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8416/nginx.confui

  2. 测试主页是否能够访问:
    # links 127.0.0.1 //若是显示Welcome to nginx! 则说明服务正常

练习:在nginx服务器上建立新的测试网页nginx.html,作本地访问测试。echo 'nginx test page.' > /usr/local/nginx/html/nginx.htmlcurl 127.0.0.1/nginx.html 显示出'nginx test page.'就说明网站服务正常

相关文章
相关标签/搜索