在Nginx上安装多个项目的语法错误

时间:2019-03-11 06:12:48

标签: nginx

我搜索了如何在Nginx服务器上安装多个项目,并找到了一些文章,例如 https://medium.freecodecamp.org/how-you-can-host-multiple-domain-names-and-projects-in-one-vps-7aed4f56e7a1

我添加了服务器名称很长的新服务器块(这是我在freenom中创建的) 检查语法时出现错误,指出server_names_hash_bucket_size必须设置为64

我尝试设置,但没有找到有效的位置。 我发现必须在http块下添加它。我试图在/ etc / nginx / sites-available / default中添加http块  但出现语法错误:

 $ sudo nginx -t 
nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/default:22 
nginx: configuration file /etc/nginx/nginx.conf test failed

我的/ etc / nginx / sites-available / default:

## 
# You should look at the following URL's in order to grasp a solid understanding 
# of Nginx configuration files in order to fully unleash the power of Nginx. 
# https://www.nginx.com/resources/wiki/start/ 
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/ 
# https://wiki.debian.org/Nginx/DirectoryStructure 
# 
# In most cases, administrators will remove this file from sites-enabled/ and 
# leave it as reference inside of sites-available where it will continue to be 
# updated by the nginx packaging team. 
# 
# This file will automatically load configuration files provided by other 
# applications, such as Drupal or Wordpress. These applications will be made 
# available underneath a path with that package name, such as /drupal8. 
# 
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples. 
## 

# Default server configuration 
# 

http { 
        server_names_hash_bucket_size 64; 
} 


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

        # SSL configuration 
        # 
        # listen 443 ssl default_server; 
        # listen [::]:443 ssl default_server; 
        # 
        # Note: You should disable gzip for SSL traffic. 
        # See: https://bugs.debian.org/773332 
        # 
        # Read up on ssl_ciphers to ensure a secure configuration. 
        # See: https://bugs.debian.org/765782 
        # 
        # Self signed certs generated by the ssl-cert package 
        # Don't use them in a production server! 
        # 
        # include snippets/snakeoil.conf; 

        # root /var/www/VotesDeploy/public; 
         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 ec2-rather-long-name.us-east-2.compute.amazonaws.com; 

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


        location ~ \.php$ { 
                include snippets/fastcgi-php.conf; 
                fastcgi_pass unix:/run/php/php7.2-fpm.sock; 
        } 

        location ~ /\.ht { 
                deny all; 
        } 



        # pass PHP scripts to FastCGI server 
        # 
        #location ~ \.php$ { 
        #       include snippets/fastcgi-php.conf; 
        # 
        #       # With php-fpm (or other unix sockets): 
        #       fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; 
        #       # With php-cgi (or other tcp sockets): 
        #       fastcgi_pass 127.0.0.1:9000; 
        #} 

        # deny access to .htaccess files, if Apache's document root 
        # concurs with nginx's one 
        # 
        #location ~ /\.ht { 
        #       deny all; 
        #} 
} 



  server { 

    listen 80; 

    root /var/www/votes/public; 

    index index.php index.html index.htm index.nginx-debian.html; 

    server_name rather-long-name-demo.demo-apps.tk; 

    location / { 
      try_files $uri $uri/ /index.php?$query_string; 
    } 


    location ~ \.php$ { 
       include snippets/fastcgi-php.conf; 
       fastcgi_pass unix:/run/php/php7.2-fpm.sock; 
    } 

    location ~ /\.ht { 
      deny all; 
    } 

    access_log /var/www/votes/storage/logs; 

#    server_names_hash_bucket_size 64; 

  } 



# Virtual Host configuration for example.com 
# 
# You can move that to a different file under sites-available/ and symlink that 
# to sites-enabled/ to enable it. 
# 
#server { 
#       listen 80; 
#       listen [::]:80; 
# 
#       server_name example.com; 
# 
#       root /var/www/example.com; 
#       index index.html; 
# 
#       location / { 
#               try_files $uri $uri/ =404; 
#       } 
#}

哪种语法有效?

修改后的方块 感谢您提供与类似主题相关的链接,但这对我没有帮助。我仍然有一个错误:

sudo nginx -t
nginx: [emerg] "http" directive is not allowed here in /etc/nginx/sites-enabled/default:2
nginx: configuration file /etc/nginx/nginx.conf test failed

在我的/ etc / nginx / sites-available / default中:

http {

    server_names_hash_bucket_size 64;


        server {   #  /var/www/html;
        listen 80 default_server;
        listen [::]:80 default_server;


        # root /var/www/VotesDeploy/public;
         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 ec2-rather-long-name.us-east-2.compute.amazonaws.com;

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


        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }

    }  // server {   #  /var/www/html;



    server { # /var/www/votes

        listen 80;

        root /var/www/votes/public;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name rather-long-name-demo.demo-apps.tk;

        location / {
          try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
          deny all;
        }

        access_log /var/www/votes/storage/logs;

    } server { # /var/www/votes



} # http {

请指出,我错过了什么语法?

谢谢!

0 个答案:

没有答案