nginx配置不生效,页面一直是默认页面welcome to nginx的解决办法

ubuntu下nginx的配置文件所在目录:html

/etc/nginx

对nginx的配置nginx

server {
    listen 80;
    server_name example.com;
    root /var/www/example;//这里是你网站程序的路径
 
    location / {
        try_files $uri $uri/ /index.html;    
    }

咱们对nginx的配置主要写在nginx.conf文件里,这个目录下还有conf.d和sites-enabled两个文件夹,里面为默认的配置文件。相应的,在配置nginx,编辑nginx.conf文件时,须要把这两行注释掉,不然nginx.conf不会生效。 ubuntu

clipboard.png

配置完毕后,检查配置文件是否正确:网站

nginx -t

clipboard.png

重启nginx使配置生效:spa

nginx -s reload

出现如下错误:code

nginx:[error] open() "/run/nginx.pid" failed (2: No such file or directory)

使用如下命令便可解决:server

nginx -c /etc/nginx/nginx.conf
nginx -s reload

其余命令:
中止nginx服务:htm

nginx -s stop
相关文章
相关标签/搜索