zoukankan      html  css  js  c++  java
  • Linux安装Nginx(yum方式 推荐)

    ## 摘抄nginx官网文档

    URL:http://nginx.org/en/linux_packages.html#stable

    1、执行如下命令 创建nginx yum配置文件

    cd /etc/yum.repos.d/

    touch nginx.repo

    [nginx-stable]
    name=nginx stable repo
    baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
    gpgcheck=1
    enabled=1
    gpgkey=https://nginx.org/keys/nginx_signing.key
    module_hotfixes=true

    chmod -R 755 nginx.repo

    Replace “OS” with “rhel” or “centos”, depending on the distribution used, and “OSRELEASE” with “6” or “7”, for 6.x or 7.x versions, respectively.

    2、执行如下命令进行yum安装nginx

    yum install nginx

    3、查看nginx版本

    # 查看nginx版本
    nginx -v
    
    # 查看编译参数
    nginx -V

    4、nginx.conf配置

    vi /etc/nginx/nginx.conf

    user  nginx;
    worker_processes  auto;
    
    error_log  /var/log/nginx/error.log notice;
    pid        /var/run/nginx.pid;
    
    events {
        worker_connections  1024;
    }
    
    http {
        include       /etc/nginx/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  /var/log/nginx/access.log  main;
    
       # sendfile        on;
       #tcp_nopush     on;
       # keepalive_timeout  65;
    proxy_connect_timeout 600s;
    proxy_send_timeout 600s;
    proxy_read_timeout 600s;
    send_timeout 600s;
    
        #access_log  /var/log/nginx/access.log  main;
    client_max_body_size 1024M;
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   300;
        types_hash_max_size 2048;
    
        #gzip  on;
        include /etc/nginx/conf.d/*.conf;
    }

    5、子配置 示例

    vi /etc/nginx/conf.d/test.conf

    server {
        listen 80;
        server_name  localhost;
        location / {
          
     # add_header Cache-Control "no-cache, no-store";
     # add_header Access-Control-Allow-Origin *;
     # add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            root /data/web;
            try_files $uri $uri/ /index.html;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location /api{
        #proxy_pass http://localhost:8888;
        }
    }

    6、测试nginx配置是否OK

    执行 nginx -t

    7、启动nginx

    cd  /usr/sbin
    
    ./nginx

    8、重新启动nginx

    nginx -s reload

  • 相关阅读:
    Linux makefile 教程 很具体,且易懂
    Java串口通信具体解释
    今年股票注定有一波行情(重申6月10号的观点)
    hotmail邮箱pop3server设置方法
    html的下拉框的几个基本使用方法
    第1次实验——NPC问题(回溯算法、聚类分析)
    【甘道夫】Hive 0.13.1 on Hadoop2.2.0 + Oracle10g部署详细解释
    C该程序生成一个唯一的序列号
    高速分拣(1)的基本算法
    Eclipse项目崩溃,使用MyEclipse解决
  • 原文地址:https://www.cnblogs.com/guliang/p/15686692.html
Copyright © 2011-2022 走看看