【nginx网站部署】【nginx部署网站】【linux-nginx】静态页面部署 静态网站部署 nginx版 前端 前端部署 web页面 nginx

============================================第一步:安装:===============================
1、安装:
sudo apt-get install nginx
输入y

2、测试是否成功:
sudo nginx -t
输出:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

3、云服务开启相关端口。
4、浏览器输入公网的 IP 回车:

Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.


=========================================第二步:指定端口/指定前端位置=====================
修改80 为指定端口如:8084。 +指定页面:

1、编辑配置文件:
sudo vi /etc/nginx/sites-available/default

按insert键:

server {
listen 8084 default_server;
listen [::]:8084 default_server;

root /usr/share/nginx/html;

index.html index.htm



----按esc 输入 :wq! -----

2、重启nginx:
cd /
service nginx restart
3、配置文件生效:
cd /usr/sbin
./nginx -s reload

4、浏览器:ip:8084

显示:
Welcome to nginx!

成功。
==================================第三步:配置ssl/https 443========================
安装记录在最后:
为了安全所有的路径必须特定-重新建立指定。再此就不做要求了选择了默认路径。

1、进入nginx:
cd /etc/nginx/
2、拷贝文件:
rz
---上传ssl 配置文件,key and crt/pem
3、添加前端主文件(css、js、xx.html等同级):
cd /usr/share/nginx/html
rz

4、添加自定义配置文件:
cd
cd /etc/nginx/conf.d
touch xxxkeji.conf
5、添加自定义配置内容:
vim xxxkeji.conf
--加入:

server {
listen 443 ssl;

server_name www.xxxkeji.com;

root /usr/share/nginx/html;

ssl_certificate xxxkeji.pem;
ssl_certificate_key xxxkeji.key;

include /etc/nginx/default.d/*.conf;

location / {
root /usr/share/nginx/html;
index index.html;
expires 30d;
}

error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

--
--保存退出:esc键 :wq
--

6、重启:
cd
service nginx restart

7、使配置生效:
cd /usr/sbin
./nginx -s reload

注意:开启云上服务器进出安全规则443端口及域名解析www、关联云服务器IP。

==================================第四步:首页设置=================================


在第三步配置文件中改首页名称,如:index.html:
location / {
root /usr/share/nginx/html;
index index.html;
expires 30d;
}

 

==================================linux基础 linux命令===============

设置新密码:
# sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
登录:
# su root
Password:

----(root@redhad:/# apt install yum
----root@redhad:/# yum install -y lrzsz)
安装文件系统:
root@ubuntu:/# apt-get install -y lrzsz
上传文件:
root@ubuntu:/# rz
--add pull file

更新:
sudo apt-get update

压缩功能

安装 sudo apt-get install rar
--卸载 sudo apt-get remove rar

解压功能

安装 sudo apt-get install unrar
--卸载 sudo apt-get remove unrar

.rar

解压:rar x FileName.rar

--压缩:rar a FileName.rar DirName
--(删除html文件夹:rm html -r 新建:mkdir html
删除文件:rm files.txt -r

--nginx安装路径:
var/lib/nginx
etc/nginx
html文件路径:
/usr/share/nginx/html

在使用vim编辑
按Esc进入命令:
输入小写:gg 至首行
再输入小写:d
再输入大写(按住Ctrl+G):G
--d为删除,G为至末尾。

cd /etc/nginx

rm -r xx.crt xx.key

 


=============================问题:================================================
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
起因:直接执行了:service nginx restart后报的错。
--------解决方法:----------

先检查nginx配置文件正否正确:
nginx -t -c /etc/nginx/nginx.conf

没问题后,再重新加载配置文件:
nginx -s reload

查看端口:
netstat -tunlp | grep 80
查看进程:
ps -ef | grep 程序名
(如:ps -ef|grep nginx)

删除进程:
kill -9 pid

(如直接访问域名报:403 Forbidden
问题原因:就是找不到页面文件,或页面文件不存在。)

posted @ 2024-08-01 19:12  刘贵庆  阅读(14)  评论(0编辑  收藏  举报