ubuntu安装nginx
2026/5/10 17:14:48 网站建设 项目流程

记录自己的外网部署步骤
1、下载nginx

sudo apt-get install nginx

2、验证版本

/usr/sbin/nginx -v # 查看nginx状态 ps -ef | grep nginx # 验证 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、常用管理命令

启动 Nginx: sudo systemctl start nginx 停止 Nginx: sudo systemctl stop nginx 重启 Nginx: sudo systemctl restart nginx (会先停止再启动,服务会有短暂中断) 重新加载配置: sudo systemctl reload nginx (平滑加载新配置,服务不中断,推荐) 开机自启: sudo systemctl enable nginx (默认已启用) 禁止开机自启: sudo systemctl disable nginx

4、启动错误

sudo systemctl start nginx # 报错 Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

查看配置文件

sudo cat /etc/nginx/sites-available/default # 查看监听端口 listen 80 default_server; listen [::]:80 default_server; # 查询端口 sudo ss -tlunp | grep :80 # 查询结果 tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users:(("python3",pid=857,fd=6)) tcp LISTEN 0 128 [::]:80 [::]:* users:(("python3",pid=857,fd=7)) # 修改监听端口 sudo vim /etc/nginx/sites-available/default # 修改结果 listen 8080 default_server; listen [::]:8080 default_server;

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询