服务器安装Nginx

news/2025/2/22 4:40:24/文章来源:https://www.cnblogs.com/techgy/p/18716020

环境

  • CentOS 8
  • 使用编译安装 Nginx

Nginx使用Docker安装确实有点麻烦,需要将很多前端文件映射到容器内部,不推荐

正式环境

1、安装环境需要的依赖包

yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2、在你的linux服务器上创建目录:nginx

cd /root && mkdir nginx

3、进入刚才安装的目录

cd nginx

4、下载并且解压安装包

wget http://nginx.org/download/nginx-1.13.7.tar.gz && tar -zxvf nginx-1.13.7.tar.gz  

5、进入刚刚解压好的目录

cd nginx-1.13.7

6、添加一些常用的模块,比如:gzip、https 模块

./configure --with-http_gzip_static_module --with-http_stub_status_module  --with-http_stub_status_module --with-http_ssl_module

7、 执行下面的命令

make && make install

make指令报错解决办法:https://blog.csdn.net/qq_45697992/article/details/120028370

8、设置 Linux 环境变量

1)编辑 /etc/profile 文件

vi /etc/profile

2)在最后一行添加下面的代码

PATH=$PATH:/usr/local/nginx/sbin
export PATH

3)让配置生效

source /etc/profile

9、任意目录下输入

nginx

10、访问服务器 IP

curl http://localhost

Nginx 常用命令

按照上面安装之后,nginx 的位置在哪里?

/usr/local/nginx/sbin

1、检查 Nginx 配置文件的语法

nginx -t

2、显示 Nginx 版本信息

nginx -v

3、查看编译时的配置参数 (大写的 V)

nginx -V

4、重启 Nginx

nginx -s stop

5、重新加载配置文件

nginx -s reload


如果出现上面的报错,就检查一下 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

解决:

sudo pkill -f nginx

强制删除 Nginx 进程,然后再重新启动

nginx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/883866.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WPF的DataGrid简单使用

简单做个记录。有时候会忘记某个样式怎么调整; 首先写一个DataGrid,AlternatingRowBackground表示隔行更改背景色;AlternationCount表示隔的行数;:1 <DataGrid Grid.Row="1" 2 AlternatingRowBackground="Snow" 3 Alternation…

报名丨Computer useVoice Agent :使用 TEN 搭建你的 Mac Assistant

与 TEN 相聚在「LET’S VISION 2025」大会,欢迎来展位上跟我们交流。这次我们还准备了一场聚焦「computer use」的工作坊,功能新鲜上线,线下首波体验!📅 TEN 展位:2025年3月1日-2日TEN workshop:2025年3月2日 13:30开始📍 上海浦东鲜花港TEN Framework 是一个主流对话…

本地AI搭建

搭建本地博客AI 目录搭建本地博客AI环境下载ollama选择模型选择embedding模型查看性能测试选择合适的嵌入模型(Embedder)估算内存选择模型量化类型介绍Q5_0 vs Q5_KQ5_K 变体(Q5_K_S、Q5_K_M、Q5_K_L)选择LLM模型下载模型下载LLM下载Embedder下载AnythingLLM配置向量数据库测试…

无需编码5分钟免费部署云上调用满血版DeepSeek

大家好,我是 V 哥。如何自己部署DeepSeek调用满血版。首先,如果你遇到了使用公共服务器时的延迟或限制,想要本地部署以获得更好的性能和稳定性。你是不是也想自己来部署DeepSeek呢,其实除了自己部署本地DeepSeek,还可以在云上免费部署满血版DeepSeek,接下来,V 哥来介绍这…

svm(support vector machine)之svr(support vector regression)学习笔记(?)

1.SVR和SVC的区分:SVR:构建函数拟合数据;SVC:二向数据点的划分(分类)注:SVR的是输入时给出的实际值 \(y_{i}\),SVC的 \(y_{i}\)是输入时给出的类别,即+1,-1。 2.SVR的目的:找到一个函数\(f(x)\),使之与训练数据给出的实际目标\(y_{i}\) 的偏差几乎不超过\(ε\),同时…

电脑必学基础操作,任何设备不白买,免费实现远程办公

随着科技的发展、时代的进步,手机、电脑、平板设备还有越来越多的软件应用已成为人们学习、工作、娱乐、社交中必不可少的工具。然而,固然这些智能化的产品益处颇多,若想要更好的掌握它们的妙用,更高效的进行使用,那可以好好了解一下一些基础操作!这不仅能够帮助我们获得…

GitLab中重置ssh密钥

1、通过命令查看当前密钥地址 ls ~/.ssh 2、从新生成新的密钥 ssh-keygen -t rsa -b 4096 -C "your-email@example.com"3、找到public key 名称为 id_rsa.pub 复制其内容,在新建密钥的时候粘贴到key中即可

网络安全红队学习资源

关于网络安全红队方向的学习资源介绍Red Team Notes 红队将模拟恶意攻击者最有可能使用的TTP,并试图获得皇冠上的宝石(通常是一面旗帜)。 https://red.tymyrddin.dev/awesome-pentest 💻🛡️ 一个为渗透测试精心策划的资源、工具和其他有趣的东西的集合。 https://githu…

利用流处理实现实时生成式 AI 应用

在过去的十年里,我们已经显著转向实时、数据中心化的应用程序。无论是在电子商务推荐、欺诈检测还是物联网事件分析中,用户现在都期望通过持续的数据流获得即时且符合上下文的响应。MongoDB 灵活的文档模型和实时能力使其非常适用于这些动态工作负载,尤其是当它与 Kafka 等流…

连续学习论文A Comprehensive Survey of Continual Learning:Theory, Method and Application阅读:

连续学习是指智能系统能够在其生命周期内逐步获取、更新、积累和利用知识的能力。主要挑战是灾难性遗忘,即学习新任务时旧任务性能急剧下降。CL 的目标包括平衡稳定性和可塑性、任务内与任务间的泛化能力以及资源效率。 2.2节对连续学习不同的种类进行了分类 包括不同任…

2025 氧化铝

跌势快要结束了

打靶记录29——dawn

靶机: https://www.vulnhub.com/entry/sunset-dawn,341/ 下载(镜像):https://download.vulnhub.com/sunset/dawn.zip 难度:中目标:获得 Root 权限攻击方法:主机发现 端口扫描 信息收集 SAMBA 漏洞 任意文件上传 日志信息泄露 调度任务 提权方法 1 提权方法 2 潜在提权方…