Serving PHP files as downloads, instead of executing them - nginx

I recently installed nginx and php 7.0.16 in my machine, but for some reason nginx downloads php files, rather than executing them. I've already spent couple of days and implemented all solutions available online, but all in vain.
My nginx.conf is:
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.fedora.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
There is no file in conf.d folder and sites-enabled has only default file that looks like below
server {
listen 80;
server_name infrastructure;
root /home/infra/index;
index index.php index.html index.htm;
#return 301 https://$server_name$request_uri;
location / {
try_files $uri $uri/ = 404;
}
# pass the PHP scripts to FastCGI server listening on the php-fpm socket
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
Can someone please advise, what could be the problem?

Found the solution. The problem was in nginx.conf file.
Replaced following line:
default_type application/octet-stream;
with:
default_type text/html;

Nginx is available as a package for Ubuntu 16.04 which we can install.
apt-get -y install nginx
Start nginx afterwards:
service nginx start
Then open localhost page and see what comes up.
Install PHP 7
We can make PHP work in nginx through PHP-FPM (PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites) which we install as follows:
apt-get -y install php7.0-fpm
PHP-FPM is a daemon process (with the init script php7.0-fpm) that runs a FastCGI server on the socket /run/php/php7.0-fpm.sock.
The nginx configuration is in /etc/nginx/nginx.conf which we open now:
nano /etc/nginx/nginx.conf
The configuration is easy to understand (you can learn more about it here: http://wiki.nginx.org/NginxFullExample and here: http://wiki.nginx.org/NginxFullExample2)
First (this is optional) adjust the keepalive_timeout to a reasonable value:
[...]
keepalive_timeout 2;
[...]
The virtual hosts are defined in server {} containers. The default vhost is defined in the file /etc/nginx/sites-available/default - let's modify it as follows:
nano /etc/nginx/sites-available/default
[...]
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;
}
}
[...]
server_name _; makes this a default catchall vhost (of course, you can as well specify a hostname here like www.example.com).
root /var/www/html; means that the document root is the directory /var/www/html.
The important part for PHP is the location ~ .php$ {} stanza. Uncomment it to enable it.
Now save the file and reload nginx:
service nginx reload
Next open /etc/php/7.0/fpm/php.ini...
nano /etc/php/7.0/fpm/php.ini
... and set cgi.fix_pathinfo=0:
[...]
; cgi.fix_pathinfo provides *real* PATH_INFO/PATH_TRANSLATED support for CGI. PHP's
; previous behaviour was to set PATH_TRANSLATED to SCRIPT_FILENAME, and to not grok
; what PATH_INFO is. For more information on PATH_INFO, see the cgi specs. Setting
; this to 1 will cause PHP CGI to fix its paths to conform to the spec. A setting
; of zero causes PHP to behave as before. Default is 1. You should fix your scripts
; to use SCRIPT_FILENAME rather than PATH_TRANSLATED.
; http://php.net/cgi.fix-pathinfo
cgi.fix_pathinfo=0
[...]
Reload PHP-FPM:
service php7.0-fpm reload
Now create the following PHP file in the document root /var/www/html:
nano /var/www/html/info.php
<?php
phpinfo();
?>
Now we call that file in a browser (e.g. http://localhost/info.php):

When using php-fpm, i uncommented this bloc in /etc/nginx/sites-available/default
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;
}

you'd need to set a location block for PHP as you did in the first
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

No need to remove php handlers,
Comment out or remove the line
#php_admin_value engine Off
it should work.

Related

How do I setup nginx for multiple web app with multiple subdomains in GCE

I am using GCE with LEMP stack. I have multiple subdomains and each subdomain has different root folder.
My setup is as below:
Production app
server {
listen 80;
listen [::]:80 ipv6only=on;
# SSL configuration
#
listen 443 ssl http2;
listen [::]:443 ipv6only=on ssl http2;
#
# 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;
ssl_certificate /etc/nginx/ssl/*.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/*.example.com.key;
server_name prod.example.com;
root /var/www/example/web;
client_max_body_size 10M;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri /app.php$is_args$args;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_read_timeout 3000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
location ~ \.php$ {
return 404;
}
}
Staging app
server {
#listen 80;
listen [::]:80;
# SSL configuration
#
#listen 443 ssl http2;
listen [::]:443 ssl http2;
#
# 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;
ssl_certificate /etc/nginx/ssl/*.example.com.crt;
ssl_certificate_key /etc/nginx/ssl/*.example.com.key;
server_name staging.example.com;
root /var/www/example-staging/web;
client_max_body_size 10M;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri /app.php$is_args$args;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_read_timeout 3000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
location ~ \.php$ {
return 404;
}
}
They have the same config except for the server_name part. But, it seems like nginx is not able to tell apart the 2 different configuration.
No matter if I were to use prod.example.com or staging.example.com, both will only route to the prod root folder.
Is there anything wrong with my configurations that is causing this issue?
The issue is because of my "staging" app is listening to IPv6 only, I need to turn on IPv4 too, so now the different subdomains are routing correctly.

Setup phpMyAdmin inside website subdirectory

I have an NGINX web server with two domains and it also runs phpMyAdmin.
phpMyAdmin is working fine and I access it through the below non-https url:
public-ip-address/phpMyAdmin
This is how the symbolic link was setup:
sudo ln -s /usr/share/phpmyadmin/ /var/www/html
Is there a way I can point phpMyAdmin to a website's subdirectory?
For example, I would like to access the phpMyAdmin login page by accessing the following URL:
domain1.com/phpMyAdmin/
How can I achieve this? domain1.com has https enabled. So it would also secure my phpMyAdmin login.
The server block is the same as the default block for NGINX. I have created a new config file by copying it to domain.com in the /etc/NGINX/sites-available folder.
The only changes are in the server and root path tags. Rest everything is default.
server domain1.com www.domain1.com;
root /var/www/domain1.com/html/
I am using certbot for Let's Encrypt SSL certificates. My server block config is shared below:
# Server Block Config for domain1.com
server {
root /var/www/domain1.com/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 domain1.com www.domain1.com;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
# 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.2-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;
#}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.domain1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = domain1.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name domain1.com www.domain1.com;
return 404; # managed by Certbot
}
Contents of /etc/nginx/snippets/fastcgi-php.conf:
# regex to split $uri to $fastcgi_script_name and $fastcgi_path
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# Check that the PHP script exists before passing it
try_files $fastcgi_script_name =404;
# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
Here is the location block that should work for you (at least the similar config works for me):
location ~* ^/phpmyadmin(?<pmauri>/.*)? {
alias /usr/share/phpmyadmin/;
index index.php;
try_files $pmauri $pmauri/ =404;
location ~ \.php$ {
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$pmauri;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
Place it before the default PHP handler location block, or the default PHP handler block will take precedence and this configuration won't work!
You can simply add another symlink to the domain1.com root, while keeping everything else same, like you did for the default domain.
sudo ln -s /usr/share/phpmyadmin/ /var/www/domain1.com/html
Am I missing something?
I came to this thread while looking for a solution to another problem (Nginx alias breaks due to try_files $uri alias bug) but since you are already using symlink to phpmyadmin for the site you access through IP, you can do the same for any domain.

Nginx won't restart . . . Job for nginx.service failed because the control process exited with error code

I am following a youtube video on setting up Nginx I'm restarting, it gives when I got the part where
I need to edit the server blocks file (sites-enabled/default) I followed exactly what they did in the video, but when saved and tried to restart:
sudo service nginx restart
I got this error:
Job for nginx.service failed because the control process exited with an error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
So I ran
systemctl status nginx.service
which gave output:
Active: failed (Result: exit-code) since Fri 2018-03-02 01:36:33 EST; 10min ago
I'm running all these on an Ubuntu 16.04 Linux VPS
below is the content of the /etc/nginx/sites-enabled/default file:
##
# 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.
# 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.
##
# Default 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.php index.html index.htm index.nginx-debian.html;
server_name x.x.x.x;
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
#
/* additions i made*/
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
try_files $uri = 404;
fastcgi_split_path_info ^(.*\.php)(/.*)$;
# 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;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root $fastcgi_script_name;
include fastcgi_params;
}
/*end of additions*/
# 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;
# }
#}
EDIT: They used php5.6 in the video but I am using PHP 7.0 if this is helpful
Something's wrong
Set up error logging to debug by editing /etc/nginx/nginx.conf:
find line with error_log, verify log file location and change the level to debug:
error_log logs/error.log debug;
Try restarting again and inspect the log file for more details.
It seems another server is running on port 443/80. so check the ports
netstat -tpln
Most probably it should be apache.
sudo killall apache2

Nginx with php7.1-fpm showing blank php pages

Background & Environment
I am attempting to deploy a Nginx server with PHP7.1-FPM, following the instructions here and here:
The server is Ubuntu 16.04
Nginx version is 1.13.3
PHP version is
PHP 7.1.9-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Sep 2 2017 05:56:43) ( NTS )
I am fairly new to all this, so compared to a seasoned linux admin, I am still somewhat ignorant of what's what, but I know enough to handle the basics.
The Issue
When I browse to a URL with as inspired01.DOMAIN.com/application/ I get a blank page. There is no entry in the nginx error log.
When I browse to a URL such as inspired01.DOMAIN.com/application/index.php I get a 404 error.
Tried so far
I have attempted the suggestions in the stackoverflow post here. As far as I could tell, my configuration already has the suggested entries that people are saying fixed this problem for them.
I was not able to resolve the issue with those answers. As that post is a few years old, I am thinking perhaps requirements have changed since then.
My Nginx configuration
My nginx.conf is:
user inspired786;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 1024;
multi_accept on;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 25;
types_hash_max_size 2048;
server_tokens off;
client_max_body_size 64m;
include /etc/nginx/mime.types;
default_type application/octet-stream;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
gzip_proxied any;
gzip_comp_level 2;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# Virtual Host Configs
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 444;
}
}
The site's conf file is:
server {
listen 80;
listen [::]:80;
server_name inspired01.DOMAIN.com;
access_log /home/inspired786/DOMAIN.com/logs/access.log;
error_log /home/inspired786/DOMAIN.com/logs/error.log;
root /home/inspired786/DOMAIN.com/public/;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Logs
No entry is generated in the Nginx server or site log.
No relevant entry is recorded to the FPM log at /var/log/php7.1-fpm.log
Question
I would like to know if there is anything obvious missing or wrong in this configuration, which would potentially result in php files not being parsed.
UPDATE
As per comment below, pasting here so anyone new sees it:
I enabled debug_connection and went through the masses of log output
that produced. As far as I could tell, there were no issues being
reported. Well, no obvious errors or warnings. So I created a
basic hello.php file including a basic echo command, and also
phpinfo. The file worked fine. So I suspect the issue is something
else. Continuing to investigate.
Consider this question on hold for now, whilst I look into some other possibilities for the blank pages issue.
I run on Linux 2.6, PHP5 and nginx
my PHP file was shown as text
After many test i change the default file in
C:\username\etc\nginx\sites-enabled
as follow:
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
After restart of nginx and PHP services PHP started working!
Check also if yours php files are under root path set in the default file
and begin tests with a test.php file as follow:
<?php
/* test.php */
phpinfo();
?>
Try to fix permissions in your project directory. In Linux this worked for me:
sudo chown -R www-data:www-data .

Why am I not able to have multiple domain names together with nginx?

I have to sub domains I want to redirect to one nginx server: first.domainOne.com and second.domainTwo.net
I have two files in my nginx sites-available directory (each file has a symlink that points to it in sites-enable):
first.server file content:
server {
root /usr/share/nginx/www;
index index.html index.htm;
server_name first.domainOne.com;
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
second.server file content:
server{
server_name second.domainTwo.net;
root /usr/share/nginx/test;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
}
When I enable both files, I am only able to access to the content of /usr/share/nginx/www (if I go to first.domainOne.com or second.domainTwo.net).
The only way I have to be able to display my second server's content (/usr/share/nginx/test) is to disable (remove) the first.server file from sites-enable.
Here is my nginx.conf :
user www-data;
worker_processes 4;
pid /var/run/nginx.pid;
events {
worker_connections 768;
}
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
gzip on;
gzip_disable "msie6";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
EDIT: Both redirections points directly to the server name (ie http://server.name) but the debug log shows it detects the two different URL used):
http://first.domainOne.com -> http://server.name
http://second.domainTwo.net -> http://server.name
server.name is the server on which my nginx instance is hosted.
What do I miss ? Are my configuration files incorrect or do I need to activate an option in nginx.conf ?
Nginx supports multiple server blocks, and your syntax looks reasonable. I suspect the problem may be with something that is not seen above. Try to keep slimming down search server block and see if you can find the problem that way. You can also try removing other files from /etc/nginx/conf.d/*.conf to continue the simplify the problem.
Following General debugging tips for Nginx may also solve your problem.
You might also try starting from simple Nginx server block examples and then building them to match your needs.
Finally, your prose mentioned that there was redirection involved, but I don't see redirection in the code your pasting. Is part of your configuration missing from what you posted? The problem could be in there.

Resources