在我的生产环境中安装和configurationnginx

我知道这里有一些愚蠢的,但我似乎无法解决这个在我的情况。 我正在安装和configurationnginx,为我的VPS提供一个有用的,更快的服务器。 我正在使用Putty命令提示符。 我正在尝试为这个项目创build自己的结构。 为什么nginx.conf语法不行? 为什么这个nginx.conftesting不成功是我无法理解的。 谁能提供一些反馈?

我得到这个错误:

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

configuration细节如下:

 # You may add here your server { server_name 123.456.789.0; return 301 $scheme://example.com$request_uri; # } # statements for each of your virtual hosts to this file ### of Nginx configuration files in order to fully unleash the power of Nginx. # http://wiki.nginx.org/Pitfalls # http://wiki.nginx.org/QuickStart # http://wiki.nginx.org/Configuration # # Generally, you will want to move this file somewhere, and start with a clean # file but keep this around for reference. Or just disable in sites-enabled. # # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.## server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /var/www/RESTfulAPI; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name example.com; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { 

看起来你在前几行缺less一些评论( # )。

更改:

 # You may add here your server { server_name 123.456.789.0; return 301 $scheme://example.com$request_uri; # } # statements for each of your virtual hosts to this file 

 # You may add here your # server { # server_name 123.456.789.0; # return 301 $scheme://example.com$request_uri; # } # statements for each of your virtual hosts to this file 

引用你的错误:

nginx:[emerg]“server”指令在/ etc / nginx / sites-enabled / default中是不允许的:18

这个问题似乎位于configuration文件顶部的第一个server指令上。

我发现有一个你已经评论过的花括号:

 # You may add here your server { server_name 123.456.789.0; return 301 $scheme://example.com$request_uri; # } # statements for each of your virtual hosts to this file 

您可能要完全评论下面的块,或删除server花括号后面的额外注释标记。