开发者社区> 问答> 正文

nginx的启动 以及配置文件修改?报错

linux下通过源码安装nginx 没有error

运行nginx  /usr/local/nginx/sbin/nginx  没有报错 但也没有提醒错误

查看8080端口的进程:(使用8080端口)

[root@localhost conf]# lsof -i:8080
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   20263 root    6u  IPv4 554416      0t0  TCP *:webcache (LISTEN)
nginx   20264  www    6u  IPv4 554416      0t0  TCP *:webcache (LISTEN

重启nginx 报错
[root@localhost conf]# service nginx restart
nginx: unrecognized service

查看nginx进程

[root@localhost conf]# ps -ef | grep nginx
root     20263     1  0 15:01 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
www      20264 20263  0 15:01 ?        00:00:00 nginx: worker process      
root     20306 19987  0 15:14 pts/2    00:00:00 grep nginx

在usr/local/nignx 中的配置文件目录是conf  但是在etc中没有nginx目录 无法找到etc/nginx/../default文件

这到底是哪里出问题了啊?


我想搭建一个http文件下载服务器,进行了以下设置

当我修改了nginx.conf的配置文件为

user  nginx nginx;
worker_processes  1;
pid        logs/nginx.pid;
worker_rlimit_nofile 102400;
#events指令时设定Nginx的工作模式及连接数上线
events {
    user epoll;
#nginx的最大连接数
    worker_connections  1024;
}
#HTTP服务器设置
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  60;
    include conf.d/*.conf;
    }
    
在nginx.conf所在目录中添加conf.d

#server标志定义虚拟主机开始
server{
#用于指定虚拟主机的服务端口
listen 80;
#server——name用来指定ip地址或域名
    server_name  localhost;
    charset utf-8;
#
    access_log  /home/tmac/sr1/logs/ access.log   jdlog;
    error_log /Home/tmac/sr1/logs/error.log error;


    location / {
#root指令用于虚拟主机的网页目录,这个目录可以是相随路径,也可以是绝对路径
       root   /home/tmac/sr1/data/
#index用于设定访问的默认首页地址
        index  index.html index.htm ;
    }
}


这样修改后

执行/usr/local/nginx/sbin/nginx

[root@localhost conf]# /usr/local/nginx/sbin/nginx
nginx: [emerg] getpwnam("nginx") failed in /usr/local/nginx/conf/nginx.conf:2

问题出在哪里啊?

我在ubuntu下安装nginx后 这样修改配置文件后启动nginx就可以实现,但现在问题好多啊!



   


展开
收起
爱吃鱼的程序员 2020-06-09 13:34:02 705 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    问题出在你没有nginx这个用户

    user nginxnginx;
    改为userwww;

    至于servicenginxrestart报错,是因为你的/etc/init.d/下没有nginx的启动脚本导致

    你可以用 /usr/local/nginx/sbin/nginx-sreload来实现配置重新加载

    用 /usr/local/nginx/sbin/nginx来启动nginx

    至于nginx停止,直接灭进程好了

    但是执行/usr/local/nginx/sbin/nginx-tnginx:theconfigurationfile/usr/local/nginx/conf/nginx.confsyntaxisoknginx:configurationfile/usr/local/nginx/conf/nginx.conftestissuccessful我按照你的方法,重新加载没有报错,启动nginx后,依然不行我在init.d中没有找到nginx所以自己新建了一个nginx在里面参照网上的填写了一个[root @localhost~]#servicenginx-tenv:/etc/init.d/nginx:Permissiondeniedchmod+x/etc/init.d/nginx 嗯嗯真心非常感谢你的热心回答!由于比较忙这么晚才回你,真心谢谢!
    2020-06-09 13:34:19
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载