全网最全的nginx服务器部署-命令行_network

news/2024/10/13 6:19:50

选用的服务器

我选用的阿文云服务器,地址是香港,优点是价格十分便宜

  1. 登录 | 阿文云计算 (xn--kcr903c616a.cn)

ssh登录服务器

我用的是ubuntu的里面的ssh去登录,用的虚拟机

ssh -l root [你的服务器地址]


ssh -l root  38.55.232.150

命令的配置

安装依赖

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

wget https://nginx.org/download/nginx-1.24.0.tar.gz

解压Nginx

解压下载的Nginx源代码包:

tar -zxvf nginx-1.24.0.tar.gz

编译和安装

进入解压后的Nginx目录并进行编译和安装:

切换到 Nginx 解压目录


cd nginx-1.24.0

编译前的配置和依赖检查


./configure

image-20240503101437643

make & make install 

image-20240503101409019

防火墙设置

如果系统本身开启防火墙,就会导致本身-->Nginx启动成功,但浏览器却不能访问的解决办法。

Nginx启动成功,但浏览器却不能访问的解决办法。_nginx启动后访问不了web-CSDN博客

如果您的系统启用了防火墙,需要关闭防火墙

安装防火墙

yum install firewalld
# 查看防火墙状态
systemctl status firewalld

# 关闭防火墙
systemctl stop firewalld
# 开机禁用防火墙
systemctl disable firewalld

开启防火墙就访问不到网页看

关闭防火墙

systemctl stop firewalld

启动Nginx

在这里启动可能会遇到端口被占用或者其他的问题,请跳到下面的问题解决

进入Nginx的安装目录:

cd /usr/local/nginx/sbin

然后,启动Nginx服务器:

./nginx

image-20240503101319845

yum install psmisc
fuser -k 80/tcpcd /usr/local/nginx/sbin./nginx 

遇到的问题

遇到端口被占用问题修改端口

image-20240503101400933

nginx安装的时候有一个坑,需要注意,那就是默认端口号配置的是80.大家知道 iis里面的服务默认也是80.如果是在windows服务里面安装的话,之前已经有iis。那么你就会报错。报端口号被占用。

[emerg] 180160#240848: bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a way forbidden by its access permissions)

为了避免的端口被占用--》修改端口


#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;try_files $uri $uri/ /index.html;}location /other/ {root   html;index  index.html index.htm;try_files $uri $uri/ /index.html;}location /template {rewrite  ^.+template/?(.*)$ /$1 break;proxy_pass  http://192.168.245.203:10001;proxy_redirect off;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}#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 
nginx -s reload
        listen       80;  #!!!!!!!!

修改成81端口就

        listen       83;  #!!!!!!!!

然后重新启动nginx,让其配置生效

./nginx -s reload

image-20240503103630030

参考链接

  1. 修改 nginx 的默认端口_nginx关闭80端口-CSDN博客
  2. Nginx启动成功,但浏览器却不能访问的解决办法。_nginx启动后访问不了web-CSDN博客---关闭防火墙

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

JDK8和JDK17共存以及切换的方法

1、先安装"jdk-8u381-windows-x64.exe",再安装"jdk-17_windows-x64_bin.exe" 2、"系统属性"-"高级"-"环境变量"-"系统变量"-"Path"-"编辑",删除以下2条 C:\Program Files\Common Files\Ora…

hgame2023 vm

vm逆向 hgame2023 vm 简单翻阅一下发现,sub_140001000里面是vm_init,sub_1400010B0是主要的vm部分查看vm_init部分,发现只知道cpu结构的大小以及初始值和24-32字节的结构,前24字节的结构未知,暂时还无法构建cpu的结构,需要更多的信息。分析下面两图的函数可以得知,opcod…

unicode编码 asis_2019_unicorn_shop

这题就是让我们购买第四个商品当我们输入price为1337.0的时候他会报错,显示要我们只输入一个字符那么我们就要想怎样用一个字符来表示一个比1337还要大的数字 答案是unicode 编码 (题目的名字给了提示) 上这个网站我们直接查看2000的unicode编码把这个编码复制一下(这就是2…

C#开源的两款功能强大的录屏神器

ScreenToGif ScreenToGif是一款由C#语言开发且开源的操作简单、免费的屏幕录制和GIF动画制作神器。它可以帮助用户捕捉计算机屏幕上的实时动画,并将其保存为高质量的 GIF 图像格式。该工具不仅适用于技术支持、软件演示和教程制作,还可以用于创建有趣的 GIF 图片和动画表情。…

linux提取具体某一行的日志文件信息出来

在 Linux 系统中提取某一行可以使用命令行工具 sed、awk、grep、head 或 tail。 以下是各个命令的用法:sed 命令sed 命令是一个强大的文本处理工具,可以用来从文件或输入流中选择、编辑、替换某一行。下面的命令提取文件 file.txt 中的第 5 行:sed -n 5p file.txt其中,-n 表…

Eclipse Memory Analyzer (MAT)的安装后提示JDK版本不对要升级到jdk_17

背景 在启动MAT分析内存时报错:Version1.8.0 of the jvm is not suitable for this product,Version17 or greater isrequired。 问题原因很明显,我电脑的JDK和JRE的环境是1.8,需要提升版本:提示需要JDK 11才可以运行,但是我的环境变量配置的是JDK 8,这咋整?不想更改环…

线性代数

线性代数 线性 对于函数 \(f(x)\)(在实数域上)是线性的,当且仅当:对于任意 \(x,y,c\),有 \(f(x+y)=f(x)+f(y)\) 和 \(f(cx)=cf(x)\)。 定义域和值域:\(c\) 是“数”,\(x\) 和 \(f(x)\) 均为“可运算的元素” 向量表示与矩阵 向量 向量 \(\vec{v}\),是一个纵向的列表,列…