全网最全Nginx服务配置

一, 安装安装Nginx

  1. 上传安装包

  2. 解压安装包

  3. 进入Nginx目录

  4. 安装依赖环境

    1
    2
    3
    yum -y install pcre pcre-devel
    yum -y install zlib zlib-devel
    yum -y install openssl openssl-devel
  5. 安装Nginx

    1
    2
    3
    4
    ./configure
    make
    make install
    安装后在/usr/local下就会有一个nginx目录
  6. 启动Nginx

    1
    2
    3
    4
    5
    6
    7
    cd /usr/local/nginx/sbin
    启动
    ./nginx
    停止
    ./nginx -s stop
    重启
    ./nginx -s reload
  7. 查看服务状态

    1
    ps -ef | grep nginx
  8. 测试Nginx服务是否成功启动

    1
    http://ip地址:80

二, 发布项目

  1. 创建一个testweb目录

    1
    2
    cd /home
    mkdir testweb
  2. 将项目上传到testweb目录

  3. 解压项目

    1
    unzip web.zip
  4. 编辑Nginx配置文件nginx-1.17.5/conf/nginx.conf

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    server {
    listen 80;
    server_name localhost;

    #charset koi8-r;

    #access_log logs/host.access.log main;

    location / {
    root /home/testweb;
    index index.html index.htm;
    }
  5. 关闭nginx服务

    1
    ./nginx -s stop
  6. 启动服务并加载配置文件

    1
    /usr/local/nginx/sbin/nginx -c /home/nginx-1.17.5/conf/nginx.conf
  7. 浏览器打开网址

    1
    http://192.168.203.138