Getting 405 when posting to php file - nginx

I have an html form which posts to to mysite.com/s/form.php, but when I submit the form I the error 405 Not Allowed. Could this be a permissions issue? Or is it something else? I'm stuck at this point.
This is my current config:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
server_name localhost;
root /var/www/mysite.com/site/;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location /s/ {
alias /var/www/mysite.com/s/;
}
}
Could someone please point out what's going wrong here?

I forgot to include the bit that makes php work, so nginx thought it was the POST was being sent to a static file, which nginx does not allow.

Related

Nginx always responding with default index.html

I am so new for deploying things.I am just trying to deploy 2 different websites with nginx. I checked a few documents and videos but my second website which knowinapp is not working as well. Whenever I am checking the website it is showing default index.html or the other my website's index.html I don't know what I am missing.
default.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
}
knowinapp.conf file
server {
listen 80;
listen [::]:80;
server_name knowinapp.com www.knowinapp.com;
root /var/www/knowinapp.com;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
The problem was about browser cache things. So, I was checked on different browser and saw the website works well... Or you can delete the cookie and site data.

Nginx SSL get blank page

I'm trying for hours to put SSL to work on nginx without success. I have already setup all things correct but i'm getting blank page when i trying to access in https. website on http work fine.
I got certificate and key from cloudflare (i already setup with it some time ago and i remember this part).
I have setup the certificate and key on /etc/nginx/ssl and my configuration of server looks like:
server {
listen 443 default default_server;
listen [::]:443 ssl default_server;
server_name myhost.com;
ssl_certificate /etc/nginx/ssl/certificate.pem;
ssl_certificate_key /etc/nginx/ssl/key.pem;
root /var/www;
index index.php index.html index.htm index.nginx-debian.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
}
I got blank page when access on https, and i don't get any erros and logs on erros/access.logs from nginx..
could someone help me?

Serving static content with nginx alias, what is the difference between /dir and /dir/?

I'm setting up an nginx server to serve an index.html page that I have stored in /data/www/test/.
Here is my config file (/etc/nginx/sites-enabled/default):
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
index index.html index.htm;
server_name localhost;
location / {
try_files $uri $uri/ =404;
}
location /test/ {
alias /data/www/test/;
index index.html;
}
}
I can curl 0:80 and see the contents of /usr/share/nginx/html/index.html.
I can curl 0:80/test/ and see the contents of /data/www/test/index.html.
But when I curl 0:80/test I get a 404.
I want to be able to see that html whether I type /test or /test/.
Can someone please explain what is happening here?
Thanks!
Just like the format, request for /test return test file, the config will match location / and find test file in root path. you can try doing touch /usr/share/nginx/html/test and access /test again
Request for /test/ will match location /test/, at the content phase, it look the index file in the root/alias specified location.

Nginx Custom error page for Individual directory

This my nginx configuration for 404 custom error page. But my problem is I'm getting custom 404 error page for all my 404 error that occurs in my server. I want to get custom error page for a particular directory only.
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.html index.htm index.nginx-debian.html;
server_name localhost;
location / {
root /var/www/html;
try_files $uri $uri/ =404;
}
error_page 404 /fail.html;
location = /fail.html {
root /var/www/html/checking/errors;
internal;
}
location /testing/([a-zA-Z]+)/ {
root /var/www/html/testing/$1;
try_files $uri $uri.html;
}
}
Assuming that what you're asking for is that when people attempt to view files of the form /testing/does-not-exist then they will see you error file, you want to move the error_page 404 /fail.html to within that location block. Where you have it right now (within the server block), it will apply to all requests. If it's for a different path that you'd like the error to show up, create a new location block for that path and then add the error_page directive to that block.

Nginx subdomains not working

I don't know what's wrong. I don't get any warnings in logs. I've similar config to this
How to exclude specific subdomains server_name in nginx configuration
I want to create subdomain us.example.io I'm using ping to check it
ping us.example.io
ping: cannot resolve us.example.io: Unknown host
nginx.config
server {
server_name *. us.example.io us.example.io;
listen 80;
root /usr/share/nginx/html/bint;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.html;
}
}
server {
server_name us.example.io;
listen 80;
return http://www.google.com;
}
The problem has nothing to do with nginx. The error suggests that you haven't configured a DNS record for the domain.

Resources