nginx sites available redirecting badly - nginx

I have a server with multiple sites running on nginx. I'm trying to add another one, and somehow I keep getting redirected to the wrong path.
What I usually do is copy from a working one and change the domain and paths, then create de symlink. I've also checked that they both have the same permissions, so I'm not seeing any mistake on my part. all paths work and of course I've restarted nginx. I also restarted the whole server out of desperation.
The failing one
server {
listen 80;
root /data/alvarezarango.com/www;
index index.php index.html index.htm;
server_name alvarezarango.com www.alvarezarango.com;
error_log /data/alvarezarango.com/logs/error.log error;
access_log /data/alvarezarango.com/logs/access.log;
location ~ [^/].php(/|$) {
fastcgi_split_path_info ^(.+?.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
the working one:
server {
listen 80;
root /data/spiraxtime.com/www;
index index.php index.html index.htm;
server_name spiraxtime.com www.spiraxtime.com;
error_log /data/spiraxtime.com/logs/error.log error;
access_log /data/spiraxtime.com/logs/access.log;
location ~ [^/].php(/|$) {
fastcgi_split_path_info ^(.+?.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
I get redirected to my main domain, but i can't see why. Is anything I can check to understand the redirects?

Related

I add nginx config of domain but my domain is not going online

I want to add a domain manually with cli of centos 7 and created a config file in sites-available directory:
server {
listen 80;
server_name hustana.ir www.hustana.ir;
location / {
root /home/www/public_html;
index index.html index.htm;
try_files $uri $uri/ =404;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
In my server there is another domains that are online and works fine.
if its help I should tell that at start my server was worked by Plesk Obtisian control panel
but now I wanna add another domain to server just but it`s not working.
I changed my domain NS from domain control center.
additional description:
I guess it`s good to say that if I delete the config block of one of my older domains , domain still stay online but it displays just a blank white page.
I tried add to include this config file from another directory directly into nginx.conf:
server {
listen 80;
server_name hustana.ir;
root /home/www/public_html;
index index.php;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
You need to enable your site as mentioned here.
Check the A-record of your domain. It must point to your server IP.

Deployment Laravel 5.4 - DigitalOcean - Nginx LEMP (16.04)

i'm deployment my laravel project in digitalocean, actually i have this situation:
DNS RECORDS - GODADDY
digitalocean ip server 104.131.16.82
DNS RECORDS DIGITALOCEAN
SERVER BLOCK ENABLED
i enabled my default server block in "/etc/nginx/sites-available/default" and created link in "/etc/nginx/sites-enabled/default" like this:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/mysite-test.com/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
return 301 $scheme://mysite-test.com$request_uri;
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;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php7-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
i followed this tutorial to install: https://gist.github.com/naveenyagati/5deec8fc40a2faaff20c629362dddf39
Actually if i go to 104.131.16.82 download a file, i don't know why, it doesn't work well, maybe i have error in server block? or DNS records?
thank you for your help!
If you have deployed using ONE CLICK APP INSTALL in Digital Ocean you have to edit the file named "digitalocean" in "/etc/nginx/site-available" directory not the "default" file for changes to take effect. If not the default LEMP landing page would be shown there.
Command to edit the main file,in digital ocean ONE CLICK APP INSTALL
sudo nano /etc/nginx/sites-available/digitalocean
Now replace the contents of the file with the following code
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/laravel/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name <Your Domain name / Public IP Address>;
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;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Replace the server_name part with your
server IP or domain name
Further reference could be found in the following gist that I have made
https://gist.github.com/naveenyagati/5deec8fc40a2faaff20c629362dddf39

NGINX and Clickonce

I am trying to get my NGINX website to work with Microsoft clickonce. I have the web site able to display the standard microsoft clickonce install page, but when I get to the Install page on my website and click the install button, nothing happens. I believe at that point it is supposed to download an EXE, which it doesn't do. Does anyone have any experience in getting clickonce to work with NGINX and what is required? Any information about setting correct directives, location, configuration, mime types or whatever else may be required.
Here is my current config file. I am new to NGINX, so perhaps it is something I am doing wrong with the location, or...?
server {
listen 80;
root /usr/share/nginx/www/MyWebSite;
index index.php index.html index.htm;
server_name MyWebSite.com www.MyWebSite.com;
client_max_body_size 100M;
access_log /var/log/nginx/MyWebSite.access.log;
error_log /var/log/nginx/MyWebSite.error.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location /Application/MyApp/ {
try_files /Application/MyApp/publish.htm /Application/MyApp/setup.exe /application/MyApp/MyApp.application;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
types {
application/x-ms-application .application;
}
}

Custom 404 page not displaying

I just started with Nginx, and did the basic configuration, regarding configuring the PHP FPM, and I've changed the index file to be index.php instead of index.html. I also managed to get a handle on URL rewriting, although omitted from my example below for simplicity.
But in the default configuration file, there is a section dedicated to error pages, which looks as if it's ready to "plug and play". I have uncommented them, but they don't work correctly. I've gone through some 404-related questions on Stackoverflow, everyone seems to recommend that as the correct syntax.
Maybe the order of instructions is wrong, however, this is from the original sample configuration, so I don't know why it wouldn't be working.
I have remove all the commented lines from the configuration file, what's left is this:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.php;
server_name localhost;
location / {
try_files $uri $uri/ index.php;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Now, when I go to http://localhost/this-page-doesnt-exist, the browser displays a literal File not found., instead of the contents of my /404.html file.
Also, the permissions of my 404.html file is the same as the permissions for the index.php, which is 644. The owner is the same as well.
What could be wrong?
try_files is passing your request for a none-existent file to index.php. This is in turn sends the request to php-fpm. By default Nginx returns the response from php-fpm to the client which is what you are seeing.
Update your php-fpm config to look like this and inform Nginx to handle error codes in the response.
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_intercept_errors on;
include fastcgi_params;
}
The documentation is here: fastcgi_intercept_errors

Nginx sites-available doesn't work

I've got this really simple server block under sites-available.
Problem: When I try to access to mydomain.com, Nginx returns a « 404 Not Found », but if I try to access to a file in particular, it works fine, like mydomain.com/index.php
server {
listen 80;
index index.php;
server_name mydomain.com;
root /home/myusername/sites/mydomain.com/htdocs;
access_log /home/myusername/sites/mydomain.com/logs/access.log;
error_log /home/myusername/sites/mydomain.com/logs/error.log;
location / {
try_files $uri =404;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
Note that:
my hosts file is configured ;
I restart Nginx after each edit ;
the access rights, user and group are correct ;
the error.log file is empty, the access.log returns me all the 404 ;
I tried to change the config by adding/removing some lines, still no changes ;
the site is enabled in sites-enabled with a correct symlink (I tried to edit it and it opened the right file) ;
I've got a few sites on the same server who runs well (so the including of sites-available and sites-enabled is OK, and Nginx works fine).
So, the answer was giver to me on ServerFault by Alexey Ten, here is a copy of the answer
Your try_files directive is too restrictive and, I guess, is in wrong place.
Either remove location / completely, it doesn't makes much sense, or, at least add $uri/ so index directive will work.
try_files $uri $uri/ =404;
But my guess is, you need to move this try_files into location ~ \.php$, this will make sure that php-file exsists before pass it to PHP-FPM for processing. All other files will be served by nginx with proper use of index directive.
server {
listen 80;
index index.php;
server_name mydomain.com;
root /home/myusername/sites/mydomain.com/htdocs;
access_log /home/myusername/sites/mydomain.com/logs/access.log;
error_log /home/myusername/sites/mydomain.com/logs/error.log;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}

Resources