当前位置: 首页> 游戏> 游戏 > 网站搭建三部曲是什么?_长沙网络开发公司_重庆白云seo整站优化_最新域名查询ip

网站搭建三部曲是什么?_长沙网络开发公司_重庆白云seo整站优化_最新域名查询ip

时间:2025/7/12 18:41:30来源:https://blog.csdn.net/Be_insighted/article/details/144255620 浏览次数:0次
网站搭建三部曲是什么?_长沙网络开发公司_重庆白云seo整站优化_最新域名查询ip

Ubuntu操作系统,Debian系统底层是Ubuntu,差异不大

ubuntu 安装nginx

1.安装依赖

sudo apt-get update

sudo apt-get install gcc

sudo apt-get install libpcre3 libpcre3-dev

sudo apt-get install zlib1g zlib1g-dev

sudo apt-get install openssl libssl-dev

2.获取压缩包,解压,配置,安装

1、下载

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

2、解压

tar xvf nginx-1.21.6.tar.gz

3、切入到解压目录

cd nginx-1.21.6

4、配置https

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module

5、编译:

make

6、安装

make install

nginx -V 查看是否有ssl模块

Nginx配置文件增加ssl相关配置

server {# xxxx平台服务listen       8211 ssl;server_name  localhost;# 引用正确的ssl证书和私钥(确保路径正确且文件存在)ssl_certificate      /home/zhqx/ssl/server.crt;  # 修正为.crt或.pem文件ssl_certificate_key  /home/zhqx/ssl/server.key;# 协议优化,仅允许安全的TLS版本和加密套件ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4:!RSA:!SHA1:!SHA256:!AES128-GCM;  # 排除一些较弱的加密套件ssl_prefer_server_ciphers  on;# 启用HSTS(HTTP Strict Transport Security),增强安全性add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload";# 防止点击劫持和跨站脚本(XSS)攻击add_header X-Frame-Options SAMEORIGIN;add_header X-Content-Type-Options nosniff;add_header X-XSS-Protection "1; mode=block";# 内容安全策略(CSP),限制资源加载来源add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; connect-src 'self' *; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:;";# 记录访问日志(可选,根据需求开启或关闭)# access_log  /var/log/nginx/sms_access.log  main;# error_log   /var/log/nginx/sms_error.log  warn;location / {root   /home/zhqx/sms/dist;index  index.html index.htm;try_files $uri $uri/ /index.html;  # 对于单页应用(SPA),确保所有路由都返回index.html}location /api {proxy_set_header        Host $http_host;proxy_set_header        X-Real-IP $remote_addr;proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header        X-Forwarded-Proto $scheme;  # 添加以传递协议信息(http/https)proxy_pass              http://ip:8092/xxx/api/v1;proxy_next_upstream     error timeout invalid_header http_500 http_502 http_503 http_504;  # 在后端服务器出错时尝试下一个服务器(如果配置了多个后端)proxy_cache_bypass      $http_upgrade;  # 对于WebSocket连接,不缓存响应}# 错误页面处理error_page 401 403 404 500 502 503 504 /custom_50x.html;location = /custom_50x.html {root   /home/zhqx/sms/error_pages;  # 指定错误页面的目录internal;  # 确保这个页面只能由Nginx内部调用}}

麒麟操作系统&Linux 安装使用yum

操作相差无几!

遇到的问题:

1:nginx: [emerg] open() "/etc/nginx/nginx.conf" failed (2: No such file or directory)

分析:

        麒麟操作系统,我在/usr/local 路径下编译安装的,但是提示这个错误!

解决:

        将nginx安装到/etc/nginx下,同时修改权限chmod 777 /etc/nginx

2:nginx: [emerg] open() "/etc/nginx/mime.types" failed (2: No such file or directory) in /etc/nginx/nginx.conf:19

分析:

        缺少mime.types文件,从网上下载一个

解决:

         sudo curl -o /etc/nginx/mime.types https://hg.nginx.org/nginx/raw-file/default/conf/mime.types

参考:
 

第一步:下载nginx压缩包
        去nginx官网下载 https://nginx.org/en/download.html

也可以直接使用wget命令下载,指令如下所示(请根据自己的需求进行下载):

建议选择官网发布的稳定版本

用命令下载时,要在自己需要下载的目录进行操作 我这里在 /home/docs/nginx 下

wget -c https://nginx.org/download/nginx-1.10.1.tar.gz


第二步:配置nginx安装所需的环境


1.安装gcc


安装 nginx 需要先将官网下载的源码进行编译,编译依赖 gcc 环境。安装指令如下:

yum install gcc-c++


2. 安装PCRE pcre-devel


Nginx的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式语法。这里需要安装两个安装包pcre和pcre-devel。第一个安装包提供编译版本的库,而第二个提供开发阶段的头文件和编译项目的源代码。安装指令如下:

yum install -y pcre pcre-devel 
 

3.安装zlib


zlib库提供了开发人员的压缩算法,在Nginx的各种模块中需要使用gzip压缩。安装指令如下:

yum install -y zlib zlib-devel
 


4.安装Open SSL


nginx不仅支持 http协议,还支持 https(即在 ssl 协议上传输 http),如果使用了 https,需要安装 OpenSSL 库。安装指令如下:

yum install -y openssl openssl-devel
 


第三步:解压nginx压缩包并安装
 

tar -zxvf nginx-1.10.1.tar.gz
解压之后,当前目录会出现一个被解压过的目录,如上图所示。

使用./configure命令来配置编译选项,如下图所示:

cd /home/docs/nginx/nginx-1.10.1
 
./configure


注意:如果需要支持https,不要直接执行 ./configure ----------------不需要忽略此命令

使用如下命令代替

./configure --with-http_ssl_module
 
--with-http_ssl_module 的意思是添加https支持
 


第四步:编译安装nginx


这里和redis的编译安装比较类似,首先在当前目录/home/docs/nginx/nginx-1.10.1进行编译。输入make即可

make
 
然后回车,如果编译出错,请检查是否前面的4个安装都没有问题。
编译成功之后,就可以安装了,输入以下指令:

make install
 
ok,安装成功。

这时会在 /usr/local/ 目录下生成一个 nginx 目录

第五步:启动nginx


以下对nginx的操作都需要进入到 /usr/local/nginx/sbin目录下执行

进入/usr/local/nginx/sbin目录,输入./nginx即可启动nginx

cd /usr/local/nginx/sbin
 
./nginx
 
关闭nginx

./nginx -s quit  或者 ./nginx -s stop
 
重启nginx

./nginx -s reload
 
查看nginx进程

ps aux|grep nginx
 
设置nginx开机启动,只需在rc.local增加启动代码即可。(这种方式好像不推荐使用)

vim /etc/rc.local
 
还需要下列命令 否则开机自启不生效

chmod +x /etc/rc.d/rc.local
 

开机自启其他配置方式

关键字:网站搭建三部曲是什么?_长沙网络开发公司_重庆白云seo整站优化_最新域名查询ip

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: