一、nginx下部署網站html
網站爲:http://10.1.75.177:8000node
nginx端口爲80nginx
配置以下:web
user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; upstream webServer { server 10.1.75.177:8000; } server { listen 80; server_name 10.1.75.177; location / { proxy_pass http://webServer/; proxy_set_header Host $host:$server_port; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } }
含義說明:bash
https://www.runoob.com/w3cnote/nginx-setup-intro.htmlapp
二、nginx爲web站點的訪問設置帳戶和密碼tcp
http://www.04007.cn/article/605.html(重點參考)網站
http://www.javashuo.com/article/p-hlcwagyp-he.html(其餘參考)orm
原配置
auth_basic_user_file /opt/modules/nginx/htpas;
修改成
auth_basic_user_file /opt/modules/nginx/htpas/htpasswd;server
建立密碼:nginx 123456
cd /opt/modules/nginx/htpas/
/usr/bin/htpasswd -bdc htpasswd nginx 123456
建立帳號後,重啓nginx
nginx -s stop
nginx
再次訪問nginx下的web,須要帳號和密碼