zoukankan      html  css  js  c++  java
  • CentOS下Nginx安装配置使用说明

    Nginx安装

    1 安装依赖包

    //一键安装四个依赖
    yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
    

    2 下载并解压安装包

    //创建一个文件夹
    cd /usr/local
    mkdir nginx
    cd nginx
    //下载tar包
    wget http://nginx.org/download/nginx-1.13.7.tar.gz
    tar -xvf nginx-1.13.7.tar.gz
    

    3 安装nginx

    //进入nginx目录
    cd /usr/local/nginx
    //进入目录
    cd nginx-1.13.7
    //执行命令
    ./configure
    //执行make命令
    make
    //执行make install命令
    make install
    

    4 配置nginx.conf

    // 打开配置文件
    vim /usr/local/nginx/conf/nginx.conf
    

    配置server

    server {
            listen       3001;
            server_name  localhost;
            root         /srv/realbim/client/dist;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                #root   html;
                try_files   $uri $uri/ @router;
                index  index.html index.htm;
            }
    
            location @router {
                rewrite ^.*$/index.html last;
    
            }
    
            location /api {
                proxy_pass http://192.168.1.224:81; 
            }
            #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$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }
    

    5 启动nginx

    /usr/local/nginx/sbin/nginx -s reload
    

    如果报错:nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed

    则运行:

    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    

    再次启动即可!

    6 查看nginx进程是否启动

    ps -ef | grep nginx
    

    7 常用命令

    安装完成一般常用命令

    进入安装目录中,

    cd /usr/local/nginx/sbin
    

    启动,关闭,重启,命令:

    ./nginx 启动
    
    ./nginx -s stop 关闭
    
    ./nginx -s reload 重启
    

    8 访问

    ping 确认ip是否通
    telnet 确认端口是否通
    systemctl stop firewalld 停止防火墙
    user root; nginx.conf用户改为root
    
  • 相关阅读:
    VMware-Fault-Tolerant Virtual Machine--论文翻译
    Mysql InnoDB存储引擎的锁相关
    深入理解JVM——读书笔记(虚拟机字节码执行引擎)
    Manacher算法
    The Google File System(论文阅读笔记)
    Java并发编程实践——读书笔记(一)
    MapReduce: Simplified Data Processing on Large Clusters
    二叉搜索树倒序O(nlogn)建树
    Day17
    Day16
  • 原文地址:https://www.cnblogs.com/fonour/p/14108349.html
Copyright © 2011-2022 走看看