Nginx安装使用

Nginx是web服务器,用于浏览器对网站的访问

Nginx软件的配置文件

启动nginx服务后,使用浏览器即可访问!

nginx配置文件

先来放一个完整的代码块

1 #user nobody; 2 worker_processes 1; 3 4 #error_log logs/error.log; 5 #error_log logs/error.log notice; 6 #error_log logs/error.log info; 7 8 #pid logs/nginx.pid; 9 10 events { 11 worker_connections 1024; 12 } 13 14 http { 15 include mime.types; 16 default_type application/octet-stream; 17 18 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 19 # '$status $body_bytes_sent "$http_referer" ' 20 # '"$http_user_agent" "$http_x_forwarded_for"'; 21 22 #access_log logs/access.log main; 23 24 sendfile on; 25 #tcp_nopush on; 26 27 #keepalive_timeout 0; 28 keepalive_timeout 65; 29 30 #gzip on; 31 32 server { 33 listen 80; 34 server_name localhost; 35 36 #charset koi8-r; 37 38 #access_log logs/host.access.log main; 39 40 location / { 41 root html; 42 index index.html index.htm; 43 } 44 45 #error_page 404 /404.html; 46 47 # redirect server error pages to the static page /50x.html 48 # 49 error_page 500 502 503 504 /50x.html; 50 location = /50x.html { 51 root html; 52 } 53 54 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 55 # 56 #location ~ \.php$ { 57 # proxy_pass http://127.0.0.1; 58 #} 59 60 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 61 # 62 #location ~ \.php$ { 63 # root html; 64 # fastcgi_pass 127.0.0.1:9000; 65 # fastcgi_index index.php; 66 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 67 # include fastcgi_params; 68 #} 69 70 # deny access to .htaccess files, if Apache's document root 71 # concurs with nginx's one 72 # 73 #location ~ /\.ht { 74 # deny all; 75 #} 76 } 77 # another virtual host using mix of IP-, name-, and port-based configuration 78 # 79 #server { 80 # listen 8000; 81 # listen somename:8080; 82 # server_name somename alias another.alias; 83 # location / { 84 # root html; 85 # index index.html index.htm; 86 # } 87 #} 88 # HTTPS server 89 # 90 #server { 91 # listen 443 ssl; 92 # server_name localhost; 93 # ssl_certificate cert.pem; 94 # ssl_certificate_key cert.key; 95 96 # ssl_session_cache shared:SSL:1m; 97 # ssl_session_timeout 5m; 98 99 # ssl_ciphers HIGH:!aNULL:!MD5; 100 # ssl_prefer_server_ciphers on; 101 102 # location / { 103 # root html; 104 # index index.html index.htm; 105 # } 106 #} 107 }

nginx的反向代理功能

proxy_pass

例上图:

当我们使用192.168.160.132访问时,nginx代理会直接跳转到192.168.160.132的8888端口

再如:

当我们使用192.168.17.129:9001/edu/访问时会跳转到8080端口

当我们使用192.168.17.129:9001/vod/访问时会跳转到8081端口

集群中的反向代理upstream

 


__EOF__

本文作者Pres1X
本文链接https://www.cnblogs.com/zyToJH/p/18014656.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   Pres1X  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· Trae初体验
点击右上角即可分享
微信分享提示