doufei2355 2013-12-16 20:05
浏览 48

使用自制软件nginx设置网站在网站上获得404? 它发生的原因是什么?

I found many links regarding this type of topic , so far i still could not solve my problem. I have just installed nginx via homebrew. Here are the steps that i did :

  1. Added site name to etc/hosts

    127.0.0.1 mysite.com
    
  2. On my usr/local/etc/nginx, i created folder using

    mkdir sites
    

    (most instructions i have read so far already have sites-enabled or sites-default on thier setup, but mine was clean so i created one.) Then within the folder i created file just using vim :

    vim mysite
    

    then in the file i have this :

    server {
      listen 80;
      server_name mysite.com;
    
      root /Users/myname/mysite/mainsite;
    
      client_max_body_size 10M;
    
      # serve static files
      location ~ ^/(images|javascript|js|css|flash|media|static)/  {
        expires 30d;
      }
    
      location / {
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php$is_args$args;
      }
    
      error_page   500 502 503 504  /50x.html;
      location = /50x.html {
         root   /opt/local/share/nginx/html;
      }
    
      location ~ \\.php$ {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
    
        fastcgi_param FF_BOOTSTRAP_ENVIRONMENT dev;
        fastcgi_param FF_BOOTSTRAP_CONFIG webroot/dev;
    
        fastcgi_buffer_size 1024k;
        fastcgi_buffers 1024 1024k;
        fastcgi_busy_buffers_size 1024k;
    
        include /usr/local/etc/nginx/fastcgi.conf;
      }
    }
    

After this i include my created folder to nginx.conf and nginx.cnf.default but after this i still get a 404 error. The above configuration on mysite file, except for some directory changes, worked on my other computer but some how i cant replicate for it to work, I tried revising and editing my directory in root but i still get 404. Did I miss some important stuff when configuring? Or what are the other possible reasons why i cannot access mysite.com after the above configuration or how i would get 404. Also i think no other background applications are currently running because i have just restarted the computer to see it the site doesnt work.. Any more suggestions why this might be happening? Thanks in advance

404 :(

  • 写回答

1条回答 默认 最新

  • doucai1901 2013-12-17 15:17
    关注

    First of all you mentioned the missing sites-enabled part, probably cause you're using centos or some other distro, I've explained this part on my answer on another question

    Your site isn't working because nginx can't see the config file, simply creating a folder in anywhere doesn't work, you need to tell nginx to look into you config file, if you're configuration is in usr/local/etc/nginx like you said, then you need to move this config file mysite to usr/local/etc/nginx/conf.d at least,

    or create the sites-available, sites-enabled pair like I explained in my other answer and move mysite to sites-available then symlink to it inside sites-enabled

    Of course make sure you point things to the right path since your nginx lives inside usr/local/etc/nginx instead of /etc/nginx

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?