美文网首页
Centos 7 下 Nginx stable安装调试

Centos 7 下 Nginx stable安装调试

作者: saronic | 来源:发表于2016-11-15 09:54 被阅读45次

    安装

    1. 在 /etc/yum.repo.d/ 下添加文件: nginx.repo,内容如下:
      官网说明点这里
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/7/$basearch/
    gpgcheck=0
    enabled=1
    
    1. Install Nginx on CentOS 7
      sudo yum install nginx
    2. Enable Nginx to start when your server boots
      sudo systemctl enable nginx
    3. Start Nginx service
      sudo systemctl start nginx
    4. Verify the Nginx Installation
      sudo systemctl status nginx
      6.其他机器浏览器打开nginx机器的IP,如果打不开,在服务器上运行 curl -I 127.0.0.1,如果显示如下,说明服务器上 nginx 运行成功了,可能是防火墙的问题。参考这里查看防火墙的状态和开放端口。
    [red@db ~]$ curl -I 127.0.0.1
    HTTP/1.1 200 OK
    Server: nginx/1.12.2
    
    

    出错后检查语法

    If the nginx server failed to start or stop or restart, check for the syntax error:

    nginx -t
    ## OR set path to config file and test for the errors ##
    nginx -c /etc/nginx/nginx.conf -t
    

    如果显示

    nginx: [emerg] getpwnam(“nginxf”) failed in /etc/nginx/nginx.conf:2
    说明没有找到 nginx 这个用户,在系统里添加 nginx 用户和组。或者在 nginx.conf里设置 nginx 使用 nobody 账户。这里添加 nginx 的用户和组。

    sudo useradd -U -s /sbin/nologin -M nginx
    # -U create a group with the same name as the user
    # -s login shell of the new account
    # -M do not create the user's home directory
    

    出现 404 或者 403 等错误

    查看 nginx 的错误日志信息,日志的路径在 nginx.conf 中配置的:error_log /var/log/nginx/error.log;

    403 Forbidden

    这个错误很可能是 selinux 造成的,先暂时关闭 selinux 试试,说明在这里。但是,测试中可以关闭 selinux,生产环境是不建议的。具体怎么设置我也不太明白,需要进一步查。

    Nginx 配置

    配置文件 /etc/nginx/nginx.conf,里面默认有 include /etc/nginx/default.d/*.conf;,所以最好不更改 nginx.conf,所有新的配置都放在 default.d 目录中,

    相关文章

      网友评论

          本文标题:Centos 7 下 Nginx stable安装调试

          本文链接:https://www.haomeiwen.com/subject/yrvkpttx.html