I'm in the process of building a LEMP stack server and local development environment, largely following the tutorials that both Linode and DigitalOcean provide. I have installed all the disparate components, but I'm a bit confused about configuring NGINX to handle PHP. The tutorials describe editing a server {}
block found in sites-available/default
. The thing is, my default configuration file has two server blocks, and I'm not sure which one I should edit.
The first contains:
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;
#}
}
While the second contains:
# 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;
# }
#}
Which should I edit? I will be working on/hosting multiple virtual hosted sites, if that makes a difference.
That are just both examples
First one is for setup default server, whit that you can handle all domains poitent to your server, so is a default vhost for domains whitout vhost.
Second one is for setup one domain "example.com"
You need create new file in sites-available/yourdomain.com
Maybe this can help you to start, this is basic configuration.
You need create user "yourdomain" for php-fpm config ( or any order user )
And for php-fpm
You also can satart whit official docs
https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/