› NGINX
› NGINX Trac
› 3rd Party Modules
› Security Advisories
› CHANGES
› OpenResty
› ngx_lua
› Tengine
在线学习资源
› NGINX 开发从入门到精通
NGINX Modules
› ngx_echo
freaks
1.01D
V2EX  ›  NGINX

nginx 缺少配置文件

  •  
  •   freaks · Jul 29, 2016 · 7402 views
    This topic created in 3760 days ago, the information mentioned may be changed or developed.

    ubuntu server 14.04 安装了 nginx 后, 本想按照网上的教程配置 vhost , 奈何没有生成 sites-available 和 sites-enable 这两个文件夹, 看别人的教程好像都有这两个文件夹, 也卸了重装没卵用, 希望大神们能指点一二,小弟不胜感激了,谢谢!

    26 replies  •  2016-07-29 18:30:46 +08:00
    wzxjohn
    wzxjohn
    Jul 29, 2016 via iPhone
    1
    1.11.3 ?你这是编译安装的吧。
    freaks
    freaks
    OP
    Jul 29, 2016
    2
    @wzxjohn 不是,就是 apt-get install nginx
    wolegequ
    wolegequ
    Jul 29, 2016 via Android
    3
    有 nginx.conf 就可以了吧
    mml
    mml
    Jul 29, 2016
    4
    你想要就自己创建就好,然后在 nginx.conf 里面加句 include 或者自己看下 nginx.conf 已经 include 了哪些目录
    freaks
    freaks
    OP
    Jul 29, 2016
    5
    @wolegequ 主配置文件修改不太好吧,大多数教程都是从 site-[available|enable]里的 default 开始的
    wolegequ
    wolegequ
    Jul 29, 2016 via Android
    6
    @freaks 大型应用没搞过,一直是直接写 nginx.conf
    freaks
    freaks
    OP
    Jul 29, 2016
    7
    @mml

    就包含了这一个目录,自己建的话要改好多,好像还要建软连接,试过了一次,没搞好
    O3YwA1ENkb7i35XJ
    O3YwA1ENkb7i35XJ
    Jul 29, 2016
    8
    把你的配置放在 /etc/nginx/conf.d/ 目录下, 文件名为 xxx.conf 即可.

    并不是所有的都按 site-(available|enable) 这种套路来的.
    mml
    mml
    Jul 29, 2016
    9
    @freaks 哪里需要改很多,不就复制一行改个路径的事情,

    你就直接写 xxx.conf 扔 conf.d 下面就好。
    freaks
    freaks
    OP
    Jul 29, 2016
    10
    @xqin @mml 我试一下咯
    yalay
    yalay
    Jul 29, 2016
    11
    觉得你这个是不是自己改源了,官方源安装应该有 site-[available|enable]的啊?
    yalay
    yalay
    Jul 29, 2016
    12
    看你现在的配置,把 xxx.conf 扔 conf.d 里就行
    wzxjohn
    wzxjohn
    Jul 29, 2016
    13
    14.04 Ubuntu 官方源 Nginx 绝对不是 1.11.3 。。。你改了 Nginx 的官方源吧。。。
    freaks
    freaks
    OP
    Jul 29, 2016
    14
    @wzxjohn @yalay 的确改了源,不会是这个原因吧
    nisekoi
    nisekoi
    Jul 29, 2016 via iPhone
    15
    你改了源,下到的 nginx 就不同了
    freaks
    freaks
    OP
    Jul 29, 2016
    17
    @nisekoi 这是我用的源,要把这两个字段删除,重新添加源吗?

    ```bash
    $ echo "deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx" >> /etc/apt/sources.list
    $ echo "deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx" >> /etc/apt/sources.list
    ```
    stormyyd
    stormyyd
    Jul 29, 2016 via Android
    18
    你在 nginx.conf 里加上一句 include /etc/nginx/site-enable/*; 然后自己建好那两个文件夹就行了
    freaks
    freaks
    OP
    Jul 29, 2016
    19
    @wingoo 感谢~ do 的文档确实不错,我现在是 nginx 和 PHP 还没结合起来, nginx 是搭建好了,但是访问 domain/info.php 不是 404 就是变成下载 info.php 这个文件
    这是我的配置文件: /etc/nginx/conf.d/default.conf

    ```
    server {
    listen 80;
    root /var/www/html;
    server_name localhost;

    #charset koi8-r;
    #access_log /var/log/nginx/log/host.access.log main;

    location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ =404;
    }
    #error_page 404 /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root /var/www/html/;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    # proxy_pass http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
    root html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
    deny all;
    }
    }
    ```
    lslqtz
    lslqtz
    Jul 29, 2016 via iPhone
    20
    我都是直接在配置文件改 conf.d 都删掉的
    freaks
    freaks
    OP
    Jul 29, 2016
    21
    @lslqtz 什么删掉? default.conf 删掉? 自己建一个配置文件
    wzxjohn
    wzxjohn
    Jul 29, 2016 via iPhone
    22
    @freaks 网上你搜到的文档基本上都是按照官方源来讲解的,你换了源目录结构就不同了,当然也就不对了呀。。。
    yalay
    yalay
    Jul 29, 2016
    23
    试试,我的配置
    server {
    .....
    location ~ .php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_read_timeout 300;
    include fastcgi_params;
    }
    }
    freaks
    freaks
    OP
    Jul 29, 2016
    24
    @wzxjohn 我又改为了官方源,但是也没有这两个文件夹
    @yalay 不行的,我们 php 版本不一致,现在掉坑里了
    kiwi95
    kiwi95
    Jul 29, 2016
    25
    哈哈,这个题目感觉楼主好蠢萌。。。不同包管理里的 nginx 好像配置文件组织方式都不太一样,这些配置的目录可以自己随意配置的,在 nginx.conf 写好就可以了
    cst4you
    cst4you
    Jul 29, 2016
    26
    新的版本, 包里好像默认没有这样的配置了, 方式改变了. 自己建立配置吧.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2109 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 01:40 · PVG 09:40 · LAX 17:40 · JFK 20:40
    ♥ Do have faith in what you're doing.