第一次用PHPconfigurationNGINX,弄不清要修改哪个服务器块

我正在构buildLEMP堆栈服务器和本地开发环境,主要是遵循Linode和DigitalOcean提供的教程。 我已经安装了所有不同的组件,但是我对configurationNGINX来处理PHP有点困惑。 这些教程描述了编辑在sites-available/defaultfind的server {}块。 事情是,我的默认configuration文件有两个服务器块,我不知道我应该编辑哪一个。

第一个包含:

 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/html; # Add index.php to the list if you are using PHP index index.html index.htm index.nginx-debian.html; server_name _; location / { # First attempt to serve request as file, then # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # include snippets/fastcgi-php.conf; # # # With php7.0-cgi alone: # fastcgi_pass 127.0.0.1:9000; # # With php7.0-fpm: # fastcgi_pass unix:/run/php/php7.0-fpm.sock; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } 

而第二个包含:

 # 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; # } #} 

我应该编辑哪一个? 如果这有所作为,我在多个虚拟托pipe站点上工作/托pipe。

这只是两个例子

第一个是设置默认服务器,你可以处理所有的领域poitent到你的服务器,所以是一个默认的虚拟主机的域名whitout虚拟主机。

第二个是设置一个域名“example.com”

您需要在sites-your / yourdomain.com中创build新文件

也许这可以帮助你开始,这是基本的configuration。

您需要为php-fpmconfiguration(或任何订单用户)创build用户“yourdomain”

 server { listen 80; server_name yourdomain.com; root /home/yourdomain; index index.html index.htm; autoindex off; ### location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini fastcgi_pass unix:/var/run/yourdomain.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 

而对于PHP的FMP

 [yourdomain] listen = /var/run/yourdomain.sock listen.owner = yourdomain listen.group = yourdomain listen.mode = 0660 user = yourdomain group = yourdomain pm = dynamic pm.max_children = 10 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 5 pm.max_requests = 0 chdir = / 

你也可以satart whit官方文档

https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/