• Nginx 编译安装

    发布于2019-02-22
  • 1、环境准备:先安装准备环境

    yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel

    2、下载nginx 安装包: 官网地址:http://nginx.org
    cd /usr/local/src
    wget http://nginx.org/download/nginx-1.12.2.tar.gz
    tar -zxvf nginx-1.12.2.tar.gz
    cd nginx-1.12.2
    ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre

    如果出现[emerg]: getpwnam(“nginx”) failed,是因为没有添加nginx用户导致的异常。
    useradd -s /sbin/nologin -M nginx

    反向代理`{
    listen 80;
    server_name www.online.net;
    return 301 http://online.net$request_uri;
    }

    server {
        listen 80;
        server_name online.net;
        access_log on;
        access_log  /usr/local/nginx/log/access.log  main;
        location / {
            proxy_pass http://online.net;
        }
    }`