Wordpress Nginx 404 - wordpress

I have a Wordpress instance running fine, and i have a directory on my server that needs to redirect users to another domain outside the main server using a 302 rule. I add this on my server block and the redirection works fine:
server {
listen 80;
server_name domain.com;
location /lps {
return 302 https://newdomain/$request_uri;
}
}
but when i go to domain.com i got a 404 Not Found error.
I also try without luck.
location / {
try_files $uri $uri/ /index.php$is_args$args;
}

I manage to solve my issue with this:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Main Server Config
server {
listen 80;
server_name localhost;
root /home/site/wwwroot;
index index.html index.htm index.php;
error_page 500 502 503 504 /50x.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location /lps {
return 302 https://newdomain.net/$request_uri;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
My Azure container have FastCGI and had to add the php instruction

Related

Nginx subdirectory 404

Hey i want install a forum (xenforo) , i already got all the .php files , i put the folder on /usr/share/nginx/html where is the page (main page index.html) , but when i do 127.0.0.1/forum/ i get that error
403 Forbidden
nginx/1.10.3
so I want to know how can I fix it, the configuration is that one
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
getenforce is disabled
When you setup Xenforo 2 on nginx you need to read the documentation here.
It tells you how to setup the nginx config like this:
location /xf/ {
try_files $uri $uri/ /xf/index.php?$uri&$args;
index index.php index.html;
}
location /xf/install/data/ {
internal;
}
location /xf/install/templates/ {
internal;
}
location /xf/internal_data/ {
internal;
}
location /xf/library/ { #legacy
internal;
}
location /xf/src/ {
internal;
}
location ~ \.php$ {
try_files $uri /index.php?$uri&$args;
#try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
This should fix your issues. That is what I'm using on centminmod and it works great. If your forum is located in the root directory remove the "/xf" from each path or if you're in a different folder, change it.

nginx - DNS works for www. but not for http://

I have a server that is using ngnix and I have a configuration file:
server {
listen 80;
server_name http://mycoolwebsite.com/;
return 301 http://www.mycoolwebsite.com$request_uri;
}
server {
listen 80;
root /var/www/website/front/public;
index index.php index.html index.htm;
server_name www.mycoolwebsite.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
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;
}
}
Now when I enter http://www.mycoolwebsite.com the website shows just fine. Whenever I enter http://mycoolwebsite.com I get:
This site can’t be reached | server DNS address could not be found.
What could be the issue here?
Your server name in the first server block should be:
server_name mycoolwebsite.com;
Also, make sure that there is a DNS entry for mycoolwebsite.com that points to your servers IP. This may be separate to the entry for www.mycoolwebsite.com.

nginx browser caching directive brings 404 not found

One of the sites I want to implement browser caching for images
has this particular server {} block on virtual.conf
server {
listen 80;
server_name www.example.net example.net;
location / {
root /var/www/example.net/public_html;
index index.html index.htm index.php;
}
error_page 404 /404.html;
location = /404.html {
root /var/www/example.net/public_html;
}
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/example.net/public_html;
}
location ~* \.(jpg|jpeg|png|gif)$ {
expires 180d;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root /var/www/example.net/public_html;
error_log /var/www/example.net/public_html/error.log error;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
Normally this directive
location ~* \.(jpg|jpeg|png|gif)$ {
expires 180d;
}
Should take care of caching images on the user end. But instead when I access
an image on my website I get 404 not found. I am not sure why this I caused.
Yes. I reloaded/restarted nginx after adding the directive.
The image resides in a subfolder like:
example.net/images/dir1/user_photos/photo.jpg
or
example.net/images/dir1/user_photos/photo.jpg
Any help would be appreciated.
Thank you.
Root parameter should be outside the location directive.
It is not the best practice to have root inside location
Change
location / {
root /var/www/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}
To:
root /var/www/html;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
}

NGINX url rewrite on digitalocean

I have problem with url rewrite from example.com to www.example.com on nginx web server. I using new hosting digitalocean.com and still struggling with this...
I will be happy with every opinion.
There is my code:
server {
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
server_name www.example.com;
root /usr/share/nginx/www;
index index.php index.html index.htm;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
I have error when I trying to restart nginx server:
Restarting nginx: nginx: [emerg] could not build the server_names_hash, you should
increase server_names_hash_bucket_size: 32
nginx: configuration file /etc/nginx/nginx.conf test failed
The server name is probably too long for the default values.
Modify the /etc/nginx/nginx.conf file by adding the following below the http:
increase server_names_hash_bucket_size: 64
Save this value and test using the -t
nginx -t
Also, watch for any saved default configurations in the sites-available folder which may cause issues.
Try the following:
server {
server_name example.com;
return 301 http://www.example.com$request_uri;
}
server {
server_name www.example.com;
root /usr/share/nginx/www;
index index.php index.html index.htm;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/www;
}
location / {
try_files $uri $uri/ /index.html;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

nginx on mac won't run php

just brewed nginx and php-fpm on my mac (10.9). I used this tutorial:
http://rtcamp.com/tutorials/mac/osx-brew-php-mysql-nginx/
So but when I set up my first "server"-blog in ngix conf, the php-files always will be downloaded, and I don't find any solutions on google.
Here's my conf:
http {
include /usr/local/etc/nginx/sites-enabled/pma.dev.conf;
include /usr/local/Sites/localsites.conf;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
server_name pma.dev;
listen pma.dev:9090;
location / {
root /usr/local/share/phpmyadmin;
index index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
include fastcgi_params;
}
}
}
You need a fastcgi_pass directive to tell nginx where your FPM server is running. Eg. fastcgi_pass 127.0.0.1:9000; if you're running it on port 9000.

Resources