好物优选点击查看详情 京东购买

暂无内容

关于Nginx搭建这事儿

Nginx搭建

Nginx是一款轻量级的Web服务器、反向代理服务器,由于它的内存占用少,启动极快,高并发能力强,在现在互联网项目中被广泛应用。 

下载地址:

以下Nginx搭建是基于docker装好的情况下,所以须在Linux,Windows, MacOS等操作系统中安装好docker; 
docker images 
docker pull nginx 
docker run --name mynginx -p 80:80 -d nginx 
docker ps 
firewall-cmd --zone=public --list-ports #查看所有开放的端口 firewall-cmd --zone=public --add-port=8080/tcp --permanent # 开放8080端口 firewall-cmd --zone=public --remove-port=8080/tcp --permanent #关闭8080端口 firewall-cmd --reload # 配置立即生效 systemctl start/stop/restart firewalld.service #打开/关闭/重启防火墙 firewall-cmd --state #查看防火墙状态 
mkdir -p /data/nginx mkdir -p /data/nginx/www mkdir -p /data/nginx/conf mkdir -p /data/nginx/logs 
docker cp 749eec3af5f8:/etc/nginx/nginx.conf /data/nginx/ docker cp 749eec3af5f8:/etc/nginx/conf.d /data/nginx/conf/ docker cp 749eec3af5f8:/usr/share/nginx/html/ /data/nginx/www/ docker cp 749eec3af5f8:/var/log/nginx/ /data/nginx/logs/ 
docker stop 749eec3af5f8 #停止容器 docker rm 749eec3af5f8 #移除容器 
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { accept_mutex on; multi_accept on; 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; #gzip on; #upstream mynginx{ # server 10.0.1.3:8088 weight=1; #} server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { # 容器中的html静态文件地址 root /usr/share/nginx/html/html; #proxy_pass http://mynginx; 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; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one #location ~ /\.ht { # deny all; #} } server { listen 80; #listen [::]:80; # 设置自己的域名服务名称 server_name www.xxx.cn; # rewrite ^(.*) https://$server_name$1 permanent; # 把http的域名请求转成https return 301 https://www.xxx.cn$request_uri; } server { # ssl 443 端口 listen 443 ssl; # 设置自己的域名 server_name www.xxx.cn; # ssl配置文件-需要解析域名通过后下载Nginx版本文件 ssl_certificate /etc/nginx/ssl/xxx.cn_bundle.crt; # ssl密钥文件-需要解析域名通过后下载Nginx版本文件 ssl_certificate_key /etc/nginx/ssl/xxx.cn.key; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; root /usr/share/nginx/html/html/PlayPlane-master; index index.html index.htm; } } include /etc/nginx/conf.d/*.conf; } 

注意:

域名需要去往腾讯云,阿里云,万网等进行域名申请;

1. 购买域名

2. 解析域名

3. 域名备案(域名若不备案会被检测,造成后期域名无法使用

docker run --name nginx -p 80:80 -p 8088:8088 -p 443:443 -v /data/nginx/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/www/html/:/usr/share/nginx/html/html/ -v /data/nginx/logs/:/var/log/nginx/ -v /data/nginx/conf/:/etc/nginx/conf.d -v /etc/ssl/nginx/:/etc/nginx/ssl/ --privileged = true -d nginx 

原文链接:https://blog.csdn.net/weixin_43869435/article/details/125439689

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享