Nginx 添加新的网站 及常见问题

1 Nginx 添加新的网站

在nginx部署新网站的时候,我的操作步骤是:

  1. ubuntu 16,已用apt-get install nginx 安装nginx
  2. 已在/etc/nginx/conf.d文件夹下添加 自定义的网站配置文件,eg abc.conf
 server {
	  listen 9000;
	  
	  # 配置域名 或 ip
	  server_name 123.56.86.151;
	  error_log /root/new54/test/error_log.log;  
	  location / {
	   
	    # 配置网站根目录
	    root  /root/new54/test; 
	    index  index.html;
	    
	    # history模式下 需要加入下面这一行,vue hash模式不需要这一行
	    try_files $uri $uri/ /index.html; 
	  }
}
  1. /etc/nginx/nginx.conf 文件中,确保此文件中存在 include /etc/nginx/conf.d/*.conf; 这行代码,表示刚刚新添加的网站已添加。

http {
    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}

2 启动Nginx

  1. 查看nginx的安装目录:whereis nginx
  2. 启动Nginx:/usr/sbin/nginx
  3. 查看进程的使用情况:ps -aux | grep nginx
  4. 查看端口占用情况:lsof -i:8080

sun的图片记录

3 解决Nginx出现403 forbidden (13: Permission denied)报错的四种方法

  1. 500 Internal Server Error
    状态图片
    原因分析:

vim /etc/nginx/nginx.conf 并且将第一行 user wwwdata 改为 user root

在这里插入图片描述
2. 确认阿里云端口已开、ufw防火墙没有禁用端口、网站配置正确的情况下:

查看ufw防火墙:ufw status
查看网站配置:请看文章标题
查看iptables:
```bash
iptables -I INPUT -p tcp --dport 49153 -j ACCEPT
```

可能是Iptables禁用了端口。
iptables

参考文章

  1. https://www.cnblogs.com/huchong/p/10031523.html(文章特别好)
配置Nginx常见问题有很多,以下是一些常见问题及其解决方法: 1. 如何启动和停止Nginx服务? - 启动Nginx:使用命令 `sudo systemctl start nginx`(在Ubuntu等系统上)或 `sudo service nginx start`(在CentOS等系统上)。 - 停止Nginx:使用命令 `sudo systemctl stop nginx`(在Ubuntu等系统上)或 `sudo service nginx stop`(在CentOS等系统上)。 2. 如何修改Nginx的默认监听端口? - 打开Nginx的配置文件,通常位于`/etc/nginx/nginx.conf`。 - 在`http`块中找到`listen`指令,可以将其更改为所需的端口号,并保存文件。 - 重加载Nginx配置:使用命令 `sudo systemctl reload nginx`(在Ubuntu等系统上)或 `sudo service nginx reload`(在CentOS等系统上)。 3. 如何配置Nginx的虚拟主机? - 在Nginx的配置文件中,可以通过添加`server`块来配置虚拟主机。 - 每个`server`块应该包括`listen`指令来指定虚拟主机监听的端口,以及`server_name`指令来指定虚拟主机的域名。 - 在`server`块内部,可以添加其他指令来配置反向代理、静态文件服务等。 4. 如何配置Nginx的反向代理? - 在虚拟主机的`server`块中,使用`location`指令来配置反向代理的目标地址。 - 例如,可以使用`proxy_pass`指令指定反向代理的目标服务器地址。 - 还可以通过其他指令来配置负载均衡、缓存等相关设置。 这些只是一些常见问题的简要解答,如果你有更具体的问题或其他需求,请随时告诉我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值