• Nginx 安装(LINUX)


    Linux 安装 Nginx

    首先判断系统中知否安装有nginx的依赖

    yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel
    

    下载nginx的安装包(或者上传到服务器)

    cd /usr/local/src/
    wget http://nginx.org/download/nginx-1.13.0.tar.gz
    tar -zxvf nginx-1.13.0.tar.gz
    

    对nginx进行编译(注意在编译的时候加入后面两个模块,后续如果用https的ssl模块没有加的话很麻烦)

    ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    # make 安装
    make && make install
    

    把nginx加入到环境变量中

    vim /etc/profile
    
    PATH=$PATH:/usr/local/nginx/sbin
    export PATH
    
    source /etc/profile
    nginx -v
    

    或者

    ln -s /usr/local/nginx/sbin/nginx /usr/bin
    

    开机启动配置

    vim /usr/lib/systemd/system/nginx.service
    
    [Unit]
    Description=nginx - high performance web server
    After=network.target remote-fs.target nss-lookup.target
     
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s stop
     
    [Install]
    WantedBy=multi-user.target
    
    # 保存生效
    systemctl daemon-reload
    # 启动服务
    systemctl start nginx.service
    # 设置开机启动
    systemctl enable nginx.service
    

    安装后Nginx的目录情况

    ​ nginx下载目录: /usr/local/src/nginx

    ​ nginx 安装目录:/usr/local/nginx

    Nginx命令:

    ​ nginx -t //检查配置文件格式是否正确

    ​ nginx //启动nginx

    ​ nginx -s stop //停止nginx

    ​ nginx -s reload //重新启动

    Nginx 初始配置

    初始化配置
    #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       8888;
            server_name  chaoran.red;
    
            #charset utf-8;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   html;
                #autoindex           on;
                #autoindex_exact_size        off;
                #autoindex_localtime                 on;
                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;
        #    }
        #}
    
    
        # 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;
        #    }
        #}
    
    }
    
  • 相关阅读:
    部署高可用keepalived组件
    Jenkins-Pipeline 流水线发布部署项目
    kubernetes Dashboard 使用RBAC 权限认证控制
    无法找到msvcp90.dll的一个碰巧解决办法
    QQ 聊天机器人小薇 1.0.1 发布!
    QQ 聊天机器人小薇 1.0.1 发布!
    Android Studio 小技巧(1):如何导入AAR文件
    <Android 基础(七)> DrawerLayout and NavigationView
    编写xml文件的几个注意事项
    <Android 基础(六)> ActionBar
  • 原文地址:https://www.cnblogs.com/wangcr/p/13577201.html
Copyright © 2020-2023  润新知