资讯动态

Nginx - 入门教程

发布时间:2026/10/24 1:39:39 来源:尧图企业网站定制
中文地址https://nginx.ac.cn/en/download.htmlNginx概念Nginx 反向代理服务器请求转发负载均衡动静分类安装启动Windows版本和Linux版本稍微有所不同Liunx中更强大1.将安装包直接解压目录最好不要带中文2.在安装目录cmd运行nginx.exe回车当看到光标在闪烁则nginx启动成功因为多路复用的特点 有可能出现两个同时运行的nginx关闭cmd窗口后不会停止在后台还是运行状态使用nginx.exe -s stop关闭nginx重启时nginx.exe -s stop先关闭再启动请求转发配置对nginx.conf进行配置Windos和Linux系统相同修改nginx启动端口号避免冲突配置nginx转发规则server{#现在对外的监听端口为9001listen9001;#目前的主机名称server_name localhost;#location固定# ~ 表示现在的匹配方式为正则匹配包含时匹配# ~ /eduservice/匹配的路径当包含了eduservice就会到8001#proxy_pass http://localhost:8001;请求转发的地址location ~ /eduservice/{proxy_pass http://localhost:8001;}}个人配置仅供进行格式和位置参考#user nobody;worker_processes1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events{worker_connections1024;}http{client_max_body_size 1024M;include 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 logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout65;#gzip on;server{listen81;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location /{root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page500502503504/50x.html;location/50x.html{root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apaches document root# concurs with nginxs one##location ~ /\.ht {# deny all;#}}server{listen9001;server_name localhost;location ~ /eduservice/{proxy_pass http://localhost:8001;}location ~ /eduuser/{proxy_pass http://localhost:8001;}location ~ /eduoss/{proxy_pass http://localhost:8002;}location ~ /eduvod/{proxy_pass http://localhost:8003;}location ~ /educms/{proxy_pass http://localhost:8004;}location ~ /educenter/{proxy_pass http://localhost:8160;}location ~ /edumsm/{proxy_pass http://localhost:8005;}location ~ /eduorder/{proxy_pass http://localhost:8007;}location ~ /staservice/{proxy_pass http://localhost:8008;}location ~ /admin/{proxy_pass http://localhost:8009;}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}}使用Nginx在前端代码中修改请求的端口号为nginx的监听端口号即可

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑