zoukankan      html  css  js  c++  java
  • nginx1.12配置

    1.创建一个用户,不能登录和不创建主目录

    useradd -s /sbin/nologin  -M nginx

    1.1安装依赖关系

    yum install gc gcc gcc-c++ pcre-devel zlib-devel openssl-devel

    2.下载nginx包

    wget -C http://nginx.org/download/nginx-1.12.0.tar.gz

    2.1 解压

    tar zxvf nginx-1.12.0.tar.gz

    2.2 编译设置

    cd nginx-1.12.0
    ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module

    若出现错误主要有一下几点:

    如果有错误提示:./configure: error: C compiler cc is not found

    解决:

    yum install gcc gcc-c++
    如果有错误提示:./configure: error: the HTTP rewrite module requires the PCRE library.
    You can either disable the module by using –without-http_rewrite_module
    option, or install the PCRE library into the system, or build the PCRE library
    statically from the source with nginx by using –with-pcre=<path> option.

    解决:

    yum install gcc gcc-c++
    如果有错误提示:./configure: error: SSL modules require the OpenSSL library.
    You can either do not enable the modules, or install the OpenSSL library
    into the system, or build the OpenSSL library statically from the source
    with nginx by using –with-openssl=<path> option.

    解决:

    yum install openssl-devel

    2.3 编译安装

    make
    make install

    3.nginx 配置文件详解

    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 localhost;

    
    

    #charset koi8-r;

    
    

    #access_log logs/host.access.log main;

    
    

    location / {
    root /var/www/html;
    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;
    }

    
    

    # 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;
    #}
    }

    
    


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    # listen 8000;
    # listen somename:8080;
    # server_name somename alias another.alias;

    
    

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    
    

    server {
    listen 8082;
    # listen somename:8080;
    server_name www.weixx.com;

    
    

    location / {
    root html/baidu;
    index index.html index.htm;
    }
    }

    
    

    # HTTPS server
    #
    #server {
    # listen 443 ssl;
    # server_name localhost;

    
    

    # ssl_certificate cert.pem;
    # ssl_certificate_key cert.key;

    
    

    # ssl_session_cache shared:SSL:1m;
    # ssl_session_timeout 5m;

    
    

    # ssl_ciphers HIGH:!aNULL:!MD5;
    # ssl_prefer_server_ciphers on;

    
    

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    
    

    }

     

    4.nginx启动以及查看是否成功

    cd /usr/local/nginx/sbin/
    ./nginx    启动
    ./nginx -s stop  停止
    ./nginx -s reload 加载配置文件

    查看端口是否开启

    netstat -tanlp |grep 80

     5.添加脚本启动

    cd /lib/systemd/system
    vim nginx.service
    [Unit]
    Description=nginx - high performance web server
    Documentation=http://nginx.org/en/docs/
    After=network.target remote-fs.target nss-lookup.target
    
    [Service]
    Type=forking
    PIDFile=/usr/local/nginx/logs/nginx.pid
    ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
    ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target

    启动nginx

    systemctl start nginx.service      #开启
    systemctl stop nginx.service   #停止
  • 相关阅读:
    IIS状态监测(如果状态错误则重启IIS)
    解决Android8.0之后开启service时报错IllegalStateException: Not allowed to start service Intent ...
    AndroidStudio 代码(导入类)报错但可正常运行,以及解决此问题后带来的系列问题解决
    No service of type Factory<LoggingManagerInternal> available in ProjectScopeService
    Android集成Google地图详细步骤记录
    Android应用图标微技巧,8.0系统中应用图标的适配
    recyclerView插入(add)和删除(remove)item后,item错乱,重复,覆盖在原recyclerView上
    Gradle依赖的统一管理,解决依赖冲突
    在博客添加网页背景动画效果,跟随鼠标移动的线条
    greendao引起的NoClassDefFoundError异常解决
  • 原文地址:https://www.cnblogs.com/weixx1111/p/8295743.html
Copyright © 2011-2022 走看看