- nginx 下载链接:
- centos7 镜像下载链接:
- 也可以在服务器上面:wget
1.创建基础目录(已经有的话 , 请跳过)
# 用来存储我们下载好的一些文件或者软件mkdir -p /home/service# 用来存储配置文件mkdir -p /home/config# 用来存储日志mkdir -p /home/logs# sh脚本mkdir -p /home/sh安装wget:yum install wget2. 下载解压nginx(复制全部 , 粘贴运行就好了)
# 没有wget 的话 , yum install wgetcd /home/servicewget tar -xzvf nginx-1.18.0.tar.gzcd nginx-1.18.03. 执行安装(复制全部 , 粘贴运行就好了)
yum -y install gcc pcre pcre-devel zlib openssl openssl-develcd /home/service/nginx-1.18.0./configure --prefix=/home/service/nginx --with-http_ssl_modulemake install4. 设置nginx自启文件(复制全部 , 粘贴运行就好了)
mkdir -p /home/config/nginxcat <<'EOF'> /home/config/nginx/nginx.service[Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=/home/service/nginx/sbin/nginx -c /home/service/nginx/conf/nginx.confExecReload=/home/service/nginx/sbin/nginx restartExecStop=/home/service/nginx/sbin/nginxstopPrivateTmp=true[Install]WantedBy=multi-user.targetEOFcp /home/config/nginx/nginx.service /lib/systemd/system/nginx.service5. 编写nginx配置(复制全部 , 粘贴运行就好了)
mkdir -p /home/logs/nginxmkdir -p /home/config/nginx/mkdir -p /home/config/nginx/conf.dcat <<'EOF'> /home/service/nginx/conf/nginx.conf#user nginx nginx;#user root;worker_processesauto;error_log/home/logs/nginx/error.log warn;#pid/var/run/nginx.pid;worker_rlimit_nofile 65535;events {use epoll;worker_connections65535;}http {includemime.types;default_typeapplication/octet-stream;fastcgi_intercept_errors on;log_formatmain'$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log/home/logs/nginx/access.logmain;limit_conn_zone $binary_remote_addr zone=conn:10m;limit_req_zone $binary_remote_addr zone=allips:10m rate=50r/s;server_names_hash_bucket_size 128;client_header_buffer_size 128k;large_client_header_buffers 4 128k;client_max_body_size 20m;client_body_timeout 120;server_tokens off;sendfileon;tcp_nopushon;keepalive_timeout65;fastcgi_connect_timeout 300;fastcgi_send_timeout 300;fastcgi_read_timeout 300;fastcgi_buffer_size 64k;fastcgi_buffers 4 64k;fastcgi_busy_buffers_size 128k;fastcgi_temp_file_write_size 128k;gzip on;gzip_min_length1k;gzip_buffers4 16k;gzip_comp_level 2;gzip_vary on;gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;include /home/config/nginx/conf.d/*.conf;}EOF# 软链ln -s /home/service/nginx/conf/nginx.conf /home/config/nginx/6. 编写80监听转发配置(复制全部 , 粘贴运行就好了)
cat <<'EOF'> /home/config/nginx/conf.d/nginx.conf#此配置文件为websocketmap $http_upgrade $connection_upgrade {default upgrade;'' close;}#upstream dist {#server127.0.0.1:8123;#}#80端口转向443#server {#listen 80;#server_name 域名.com,www.域名.com;#return 301 https://www.域名.com$request_uri;#}#非www重定向www#server { #listen 443; #server_name 域名.com; #return 301 https://www.域名.com$request_uri;#}server {listen80;#listen443 default_server ssl;#server_namewww.域名.com;server_namelocalhost;root /home/service/nginx/html;index index.html index.htm;#location ~*\.(gif|jpg|jpeg|png|bmp|swf|css|js|html)$ {#root /home/service/nginx/html;#}#下载目录#location /download {#rewrite ^/download/(.*)$ /$1 break;#add_headerContent-Type"application/octet-stream;charset=utf-8";#add_headerContent-Disposition "attachment; filename*=utf-8'zh_cn'$arg_n";#root /home/www/html/downloadF;#autoindex on;#autoindex_exact_size off;#}#配置https#ssl_certificate /home/config/nginx/sslfile/1_www.域名.com_bundle.crt;#ssl_certificate_key /home/config/nginx/sslfile/2_www.域名.com.key;#ssl_protocols TLSv1 TLSv1.1 TLSv1.2;#ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;#ssl_prefer_server_ciphers on;#ssl_session_cacheshared:SSL:10m;#ssl_session_timeout 10m;#ssl_buffer_size 1400;location /api {proxy_http_version 1.1;proxy_set_header Connection "";proxy_connect_timeout 60s;proxy_read_timeout 60s;proxy_send_timeout 60s;proxy_buffer_size 512k;proxy_bufferingon;proxy_buffers8 512k;proxy_busy_buffers_size 1024k;proxy_max_temp_file_size 100M;proxy_pass ; #http://distproxy_redirectoff;proxy_set_headerHost $host;proxy_set_headerX-real-ip $remote_addr;proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection 'upgrade';proxy_set_header Origin "";#限制TCP并发连接数100/slimit_conn conn 100;}}EOFsystemctl enable nginx.servicesystemctl start nginx.serviceservice nginx status
推荐阅读
-
短发|李溪芮难得留长发,扎起头发更有味道了,筷子腿赚足了眼球
-
美国|白宫对华施压过猛,终于发现不对劲,美国正在丢失斗志
-
萌娘ACG研究所|那些作为全日本男人情敌的女人后来怎样了?
-
爱烁烁▲上学的时候开家长会都是我妈去。有一次我妈单位有事就派我爸去了
-
生气导致胸闷、气短、头晕等,背后的机理是啥有啥缓解的办法
-
香香美食分享|不知道的还以为是买的,简单易学,皮香肉嫩,一招教你做甜皮鸭腿
-
-
青年|有种惊艳叫陈妍希,减肥后大秀“辣妈腿”,这颜值还配不上陈晓?
-
青藤录下|律师团去哪了?,郑爽太惨了!亲自带粉丝反黑后求饶:来不了
-
央视新闻客户端|日本新增622例新冠肺炎确诊病例 累计确诊23657例
-
简明科学指南 操作系统,祝你祝你13岁生日快乐,Android
-
青年地方无权对“数据权”立法?深圳数据条例意见稿引专家热议
-
减肥|心理减肥之父王歌导师:分析不良的生活饮食和生活习惯是哪些呢?
-
-
「百万逗逗」小心你的身体,早知早健康!,鸡蛋切记不可和它一起
-
邓超|他和邓超斗了10年,如今邓超成影帝,他却四处求人拍戏
-
微凉秋陌|跨场景互动,神器换种方式拿,魔兽世界:橙锤出现在“猎人”世界
-
-
新资讯|《中餐厅》黄晓明突然cue冯绍峰,赵丽颖的反应,够我看100遍
-