【问题标题】:Add domain to Nginx config将域添加到 Nginx 配置
【发布时间】:2016-02-27 12:11:57
【问题描述】:

这是我的问题

我有域“example.com”,我希望该域与文件夹 /var/www/html/example.com 相关联

我在 /etc/nginx/sites-available 中创建了名为“example.com”的文件

server {
    server_name http://example.com;

    root /var/www/html/example.com;
    index index.html index.php;

    # set expiration of assets to MAX for caching
    location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
            expires max;
            log_not_found off;
    }

    location / {
            # Check if a file or directory index file exists, else route it to index.php.
            try_files $uri $uri/ /index.php;
    }

    location ~* \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            include fastcgi.conf;
    }

这是我在 /etc/nginx/sites-enabled 上的默认文件

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    # SSL configuration
    #
    # listen 443 ssl default_server;
    # listen [::]:443 ssl default_server;
    #
    # Self signed certs generated by the ssl-cert package
    # Don't use them in a production server!
    #
    # include snippets/snakeoil.conf;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name 188.226.145.195;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }

    location /example.com/ {
            try_files $uri $uri/ /example.com/index.php;
    }

我知道问题出在根目录 /var/www/html 但无法解决

错误日志:

2016/02/27 13:53:53 [error] 10139#0: *11 directory index of "/var/www/html/" is forbidden, client: xxx.xx.xx.xx, server: 188.226.145.195, request: "GET / HTTP/1.1", host: "www.example.com"

希望这是足够的信息,因此 some1 可以提供帮助。 谢谢。

【问题讨论】:

  • server_name 语法错误(请参阅this)。另外,您是否将新的可用站点文件符号链接到启用站点的目录?
  • 是的,它在启用站点的链接中链接我修复了 server_name,现在得到了新错误 2016/02/28 14:07:32 [error] 11045#0: *317 connect() failed (111: Connection refused) while connecting to upstream, client: 93.123.47.139, server: example.com, $request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "example.com"
  • 新的错误提示9000端口的服务没有运行。

标签: nginx


【解决方案1】:

我做到了,问题是我没有将 root 设置为默认位置,当我这样做时,它就像一个魅力:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 2012-04-11
    • 2016-04-09
    • 1970-01-01
    • 2018-08-31
    相关资源
    最近更新 更多