服务器安装 Nginx
环境
-
CentOS 7
-
服务器存储一个快照方便后面安装失败回滚
-
使用编译安装 Nginx
Docker 还是直接安装 ?
Nginx 使用 Docker 安装属实有一些麻烦,各种前端文件还需要映射到容器内部,不是很推荐
正式安装
1、安装环境需要的依赖包
▼Bash复制代码yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
2、在你的linux服务器上创建目录:nginx
▼bash复制代码cd /root && mkdir nginx
3、进入刚才安装的目录
▼bash复制代码cd nginx
4、下载并且解压安装包
▼bash复制代码wget http://nginx.org/download/nginx-1.13.7.tar.gz && tar -zxvf nginx-1.13.7.tar.gz
5、进入刚刚解压好的目录
▼text复制代码cd nginx-1.13.7
6、添加一些常用的模块,比如:gzip、https 模块
▼bash复制代码./configure --with-http_gzip_static_module --with-http_stub_status_module --with-http_stub_status_module --with-http_ssl_module
PS 这个 nginx error log 不是报错,别看到红就紧张(像我一样🤣)
7、 执行下面的命令
▼bash复制代码make && make install
安装成功后的截图
8、设置 Linux 环境变量
1)编辑 /etc/profile 文件
任意目录下执行下面的命令
▼text复制代码vi /etc/profile
2)在最后一行添加下面的代码
▼bash复制代码PATH=$PATH:/usr/local/nginx/sbin export PATH
3)让配置生效
▼bash复制代码source /etc/profile
9、任意目录下输入
▼bash复制代码nginx
10、访问服务器 IP
Nginx 常用命令
按照上面安装之后,nginx 的位置在哪里?
▼bash复制代码/usr/local/nginx/sbin
1、检查 Nginx 配置文件的语法
▼bash复制代码nginx -t
2、显示 Nginx 版本信息
▼bash复制代码nginx -v
3、查看编译时的配置参数 (大写的 V)
▼bash复制代码nginx -V
4、重启 Nginx
▼bash复制代码nginx -s stop
5、重新加载配置文件
▼bash复制代码nginx -s reload
如果出现上面的报错,就检查一下 nginx 配置文件
Nginx 配置文件
下面是默认的 Nginx 配置文件
▼nginx复制代码#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { 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_timeout 65; #gzip on; server { listen 80; 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_page 500 502 503 504 /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 Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # 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 -s reload 时报错 nginx: [error] invalid PID number
解决:
▼bash复制代码sudo pkill -f nginx
强制删除 Nginx 进程,然后再重新启动
▼bash复制代码nginx
相关专栏
评论
问答助学
相关内容
0个评论
全部评论
点击登录,快来和大家讨论吧~
表情
图片
暂无评论
内容推荐
GPT-5.6 Sol、Terra、Luna 怎么选?看这一篇就够了
3
🛰️ dtSpaceMap - 实时卫星追踪 3D 可视化平台
5
AI应用开发中的流式输出:从协议原理到工程实战的完整指南
38
第1章 LearnWise AI项目介绍
5
【入职求助贴】萌新刚入职某大厂做后端开发,目前还在试用期。最近遇到一个棘手的问题,想向大家求助一下。入职不久,leader 给我派了一个任务。跟我说是0.5天就可以解决,我刚毕业入职,做了一个星期没有做出来。实现一个收集定时成功任务的案例。听起来好像不复杂,但我自己摸索着做了一整个星期,到现在还没达到预期效果。这一周我基本是“边学边做”的状态,遇到卡点也会每天主动找 leader 沟通进度和疑问。
2
作者分享
Spring 团队开发者布道师 Josh Long,从 2011 年起每周二坚持写 This Week in Spring https://spring.io/authors/joshlong,大概 15 年半从未间断,到现在大概写了 800 期以上😱
大佬在采访里他说,写博客不是额外负担,而是逼自己整理每周所学的「强制机制」——反正本来就会刷社区动态,写出来既方便自己,也帮到别人。更重要的是 Spring 一直在变:微服务、AI……永远有新东西可聊,停一周就容易掉队。一旦养成习惯,坚持往往比重新开始更容易。
这种级别的大佬都还在用周更逼自己不掉队,我更没理由再拖了。还有之前左耳朵耗子大佬说的 ARTS 打卡,我老实说只撑了两周,真的需要捡起来了,加油✊
10
试了下 Grok CLI:curl -fsSL https://x.ai/cli/install.sh | bash 虽然功能不如 Claude Code 全,但能免费用 Grok 4.5 啊😍。一行 prompt 大概 3 分钟就生成出来了而且没有报错:" Three.js UMD 构建。正在实现完整的太阳系模拟(含自定义轨道控制,兼容本地打)"。
大伙可以访问试试:https://solar-system-seven-mocha.vercel.app/
4
彻底搞懂 Spring AI Tool Calling:从底层协议到源码执行全流程
7
别用 JWT 管理用户会话
9
没想到 Bot 占全球 HTML 流量的 50% 以上了,被这个比例给震惊到了。还有开发者在评论区说自己的网站「每天」访问量 250k 但是 Cloudflare 显示真实的用户只有 150 个😱
数据来源:https://radar.cloudflare.com/traffic#bot-vs-human
5

