Nginx没有开始,自制软件说它是

时间:2017-01-04 14:30:30

标签: macos nginx homebrew

brew服务说nginx已经启动..

MacBook-Pro-van-Youri:Homebrew youri$ brew services start nginx
Service `nginx` already started, use `brew services restart nginx` to restart.

与launchctl相同

MacBook-Pro-van-Youri:Homebrew youri$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist 
/Users/youri/Library/LaunchAgents/homebrew.mxcl.nginx.plist: service already loaded

我的homebrew.mxcl.nginx.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>homebrew.mxcl.nginx</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/opt/nginx/bin/nginx</string>
        <string>-g</string>
        <string>daemon off;</string>
    </array>
    <key>WorkingDirectory</key>
    <string>/usr/local</string>
  </dict>
</plist>

brew服务列表说明如下:

MacBook-Pro-van-Youri:LaunchAgents youri$ brew services list
Name    Status  User  Plist
mariadb started youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
nginx   error   youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.nginx.plist
php71   started youri /Users/youri/Library/LaunchAgents/homebrew.mxcl.php71.plist

语法是oke:

MacBook-Pro-van-Youri:LaunchAgents youri$ plutil -lint homebrew.mxcl.nginx.plist 
homebrew.mxcl.nginx.plist: OK

当我运行sudo nginx时,我可以访问我的网站

2 个答案:

答案 0 :(得分:13)

因为nginx将从端口80开始,所以它必须是root。

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

移动homebrew.mxcl.nginx.plist

sudo mv ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

从LaunchDaemons文件夹中加载plist

sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

现在,sudo brew services list显示正在运行的nginx进程

Name    Status  User  Plist
nginx   started root  /Library/LaunchDaemons/homebrew.mxcl.nginx.plist

在没有root的情况下运行brew services list将导致错误状态,因为您需要是root才能读取状态

答案 1 :(得分:0)

如上所述,这是因为保留了端口80,所以它必须是root。

一种更简单的方法是使用sudo运行sudo brew services start nginx

<?php

namespace App\Controller;

use App\Entity\Ad;
use App\Form\AdType;
use App\Repository\AdRepository;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class AdController extends AbstractController
{
    /**
     * @Route("/ads", name="ads_index")
     */
    public function index(AdRepository  $repo)
    {
        $ads = $repo->findAll();

        return $this->render('ad/index.html.twig', [
            'ads' => $ads,
        ]);
    }

    /**
     * @Route("/ads/new", name="ads_create")
     * 
     * @return Response
     */

    public function create(Request $request, ObjectManager $manager){
        $ad = new Ad();



        $form = $this->createForm(AdType::class, $ad);

        $form->handleRequest($request);//symfony va faire le lien entre les donne des champs fu formulaire et la variable $ad

        if($form->isSubmitted() && $form->isValid() ){
            $manager->persist($ad);
            $manager->flush();
        }

        return $this->render("ad/new.html.twig", [
            'form' => $form->createView()
        ]);
    }

    /**  
     * @Route("/ads/{slug}", name="ads_show")
     * @return Response
     */
    public function show(Ad $ad){
        return $this->render('ad/show.html.twig', [
            'ad' => $ad
        ]);
    }
}