靓靓小知识-Nginx安装及配置文件

Nginx安装及配置文件-centos7

1.下载解压安装包

wget http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0/
#安装所需依赖
yum -y install gcc pcre-devel openssl openssl-devel

目录结构如下
在这里插入图片描述

2.源码编译安装

编译方案有多种,仅供参考

./configure \
--prefix=/u01/nginx117 \
--conf-path=/u01/nginx117/conf/nginx.conf \
--pid-path=/u01/nginx117/conf/nginx.pid \
--lock-path=/u01/nginx117.lock \
--error-log-path=/u01/nginx117/logs/error.log \
--http-log-path=/u01/nginx117/logs/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/u01/nginx117/client \
--http-proxy-temp-path=/u01/nginx117/proxy \
--http-fastcgi-temp-path=/u01/nginx117/fastcgi \
--http-uwsgi-temp-path=/u01/nginx117/uwsgi \
--http-scgi-temp-path=/u01/nginx117/scgi \
--with-http_ssl_module \
--with-stream_ssl_module
--prefix=PATH                           指定nginx的安装目录。
--conf-path=PATH                        设置nginx.conf配置文件的路径。nginx可使用不同的配置文件启动,通过-c选项。
--pid-path=PATH                         指定nginx的pid目录
--lock-path=PATH                        指定nginx的lock目录(nginx.lock,安装文件锁定)
--error-log-path=PATH                   指定nginx的错误日志目录
--http-log-path=PATH                    指定nginx的访问日志目录
--with-http_gzip_static_module          添加nginx的gzip模块
--http-client-body-temp-path            添加nginx的客户端自定义模块
--http-proxy-temp-path                  nginx的代理临时目录
--http-fastcgi-temp-path                nginx的快速访问临时目录
--http-uwsgi-temp-path                  nginx的sgi临时目录
--http-scgi-temp-path                   nginx的scgi临时目录
--with-http_ssl_module                  添加nginx的https协议模块
--with-stream_ssl_module                添加ssl协议必要支持

在这里插入图片描述

3.编译

make

4.安装

make install

5.目录结构

在这里插入图片描述
nginx.conf文件配置通用参数,具体端口的配置文件全部在vhosts下面,避免单个配置文件太混乱

6.nginx.conf参考

worker_processes  auto;
worker_rlimit_nofile 65535;
user root;
error_log       /u01/nginx117/logs/error.log warn;
events {
        use epoll;
        worker_connections 65535;
        multi_accept on;
        }

http {
        include mime.types;
        default_type application/octet-stream;
        charset utf-8;
        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;
         #access_log  "pipe:rollback logs/access_log interval=1d baknum=7 maxsize=2G"  main;
        server_names_hash_bucket_size 128;
        client_header_buffer_size 64k;
        client_max_body_size 100m;
        client_body_buffer_size 1024k;
        large_client_header_buffers 4 64k;
        server_tokens off;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 120;
        ssl_session_cache shared:SSL:50m;
        ssl_session_timeout 5m;
        server_name_in_redirect off;
        proxy_connect_timeout 300;
        proxy_read_timeout 180;
        proxy_send_timeout 180;
        proxy_buffering    off;
        proxy_buffer_size 128k;
        proxy_buffers 100 128k;
        proxy_busy_buffers_size 128k;
        proxy_temp_file_write_size 128k;
       # proxy_temp_path /u01/nginx117/tmp/proxy_temp_dir;
       # proxy_cache_path /u01/nginx117/tmp/proxy_cache_dir levels=1:2 keys_zone=cache_one:1000m inactive=10d max_size=30g;
        gzip on;
        gzip_min_length 1k;
        gzip_buffers 4 32k;
        gzip_comp_level 6;
        gzip_types text/plain text/css text/xml text/javascript application/json application/x-javascript application/xml application/xml+rss;
        open_file_cache max=204800 inactive=30s;
        open_file_cache_min_uses 2;
        open_file_cache_valid 30s;
        open_file_cache_errors on;
        limit_conn_zone $binary_remote_addr zone=TotalConnLimitZone:10m ;
        #limit_conn  TotalConnLimitZone  200;
        limit_conn_log_level notice;
        limit_req_zone $binary_remote_addr zone=ConnLimitZone:10m  rate=500r/s;
        limit_req_log_level notice;
        include vhosts/*.conf;
}

7.vhosts目录下参考

在这里插入图片描述

server{
                        listen 80;
                        server_name 127.0.0.1;
                        index index.html index.htm;
                        root /u01/www/web/dist;
                        location ~* ^.+\.(eot|ttf|otf|woff|svg)$ {
                                expires max;
                        }

                        location / {
                                add_header 'Access-Control-Allow-Origin' '*';
                                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                                #add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
                                try_files $uri $uri/ @router;
                                if ($request_method = 'OPTIONS') {
                                        return 204;
                                }
                        }
                         location @router {
                                rewrite ^.*$ /index.html last;
                        }

                         location ^~ /api/ {
                                proxy_pass http://127.0.0.1:81/;

                        }

                        location /ws {
                                proxy_pass http://127.0.0.1:81;
                                proxy_read_timeout 300s;
                                proxy_http_version 1.1;
                                proxy_set_header Upgrade $http_upgrade;
                                proxy_set_header Connection "upgrade";
                                proxy_set_header X-real-ip $remote_addr;
                                proxy_set_header X-Forwarded-For $remote_addr;
                        }

                        location /logs {
                                alias /data/logs/;
                                autoindex on;
                        }

                        location /upload {
                                alias /data/upload;
                        }
                        location /static/(.*).(js|jpg|jpeg|png|css) {
                                expires 12h;
                        }

                        #location /nginx_status {
                        #       stub_status on;
                        #access_log off;
                        #}
     }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值