Nginx Wordpress can't access blog posts but homepage accessible - php

Nginx version: nginx/1.10.0 (Ubuntu 16.04)
This is my blog conf:
server {
listen 80;
server_name blog.khophi.co;
root /var/www/html/blog;
index index.php;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
location ~ /\.ht {
deny all;
}
}
As per steps here and here and here
I am able to visit the site homepage, but the article pages, like myblog.example.com/this-is-my-article doesn't work.

This might help,
just review every single line and remove which that you think you don't need,
its the config I always used for every wordpress setup
server {
listen 80;
server_name www.xxxxyour-domainxxxxx.com xxxxyour-domainxxxxx.com;
return 301 https://xxxxyour-domainxxxxx.com$request_uri;
}
server {
#listen 80;
listen 443 default_server ssl spdy;
server_name xxxxyour-domainxxxxx.com;
ssl on;
ssl_certificate /var/www/xxxxyour-domainxxxxx.com/noyoucant/xxxxyour-domainxxxxx.crt;
ssl_certificate_key /var/www/xxxxyour-domainxxxxx.com/noyoucant/xxxxyour-domainxxxxx.key;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 10s;
client_max_body_size 64m;
client_body_timeout 60;
#access_log /var/www/xxxxyour-domainxxxxx.com/xxxxyour-domainxxxxx.com.log;
error_log /var/www/xxxxyour-domainxxxxx.com/xxxxyour-domainxxxxx.com-error error;
root /var/www/xxxxyour-domainxxxxx.com;
index index.html index.php;
location / {
gzip_static on;
error_page 418 = #cachemiss;
if ($request_method = POST) { return 418; }
if ($query_string != "") { return 418; }
if ($http_cookie ~* "wordpress_logged_in_") { return 418; }
if ($http_cookie ~* "comment_author_") { return 418; }
if ($http_cookie ~* "wp_postpass_") { return 418; }
try_files "/wp-content/cache/all${uri}index.html" =418;
add_header "X-WPFC-Cache" "HIT";
# choose or modify any of the following cache-control headers
expires 30m;
# add_header "Cache-Control" "max-age=10, must-revalidate";
# add_header "Vary" "Cookie";
}
location #cachemiss {
try_files $uri $uri/ /index.php$is_args$args;
}
### SECURITY ###
error_page 403 =404;
location ~ /\. { access_log off; log_not_found off; deny all; }
location ~ ~$ { access_log off; log_not_found off; deny all; }
location ~* wp-admin/includes { deny all; }
location ~* wp-includes/theme-compat/ { deny all; }
location ~* wp-includes/js/tinymce/langs/.*\.php { deny all; }
location /wp-includes/ { internal; }
#location ~* wp-config.php { deny all; }
location ~* ^/wp-content/uploads/.*.(html|htm|shtml|php)$ {
types { }
default_type text/plain;
}
### DISABLE LOGGING ###
location = /robots.txt { access_log off; log_not_found off; }
location = /favicon.ico { access_log off; log_not_found off; }
### CACHES ###
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ { access_log off; expires max; }
location ~* \.(woff|svg)$ { access_log off; log_not_found off; expires 30d; }
location ~* \.(js)$ { access_log off; log_not_found off; expires 7d; }
### php block ###
location ~ \.php?$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_hide_header X-Powered-By;
#fastcgi_pass 127.0.0.1:9001;
fastcgi_pass unix:/xxxx/dir/php-fpm/php-fpm.sock;
#fastcgi_pass fpm;
add_header "X-WPFC-Cache" "MISS";
}
}

Related

Wordpress config misbehaving in opposite ways using two configs

If I have this config in sites-available in nginx for the aforementioned wordpress site, it will not display the root page (403 error), but it will display specific pages if I enter their URL manually, such as https:// subdomain.domain.tld/suchandsuch
server {
listen 80;
server_name subdomain.domain.tld;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
## Your website name goes here.
server_name subdomain.domain.tld;
## Your only path reference.
root /var/www/subdomain.domain.tld;
ssl_certificate /etc/letsencrypt/live/subdomain.domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/subdomain.domain.tld/privkey.pem;
## This should be in your http block and if it is, it's not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
#fastcgi_pass php;
#The following parameter can be also included in fastcgi_params file
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
However if I have this config set, it will do the opposite - it will show the root page, but any other pages I click on gives a 404 error:
server {
listen 80;
server_name subdomain.domain.tld;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name subdomain.domain.tld;
root /var/www/subdomain.domain.tld;
index index.php index.html;
access_log /var/log/nginx/subdomain.domain.tld-access.log;
error_log /var/log/nginx/subdomain.domain.tld-error.log;
ssl_certificate /etc/letsencrypt/live/subdomain.domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/subdomain.domain.tld/privkey.pem;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}
Could some part of each config be needed to be combined together to make a working config for wordpress?
I expected the wordpress files and MySQL database to function as it had on the Apache server I had it on previously.
ChatGPT did a bang-up job of helping me figure this out.
Here is the final config:
server {
listen 80;
server_name subdomain.domain.tld;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name subdomain.domain.tld;
root /var/www/subdomain.domain.tld;
index index.php index.html;
access_log /var/log/nginx/subdomain.domain.tld-access.log;
error_log /var/log/nginx/subdomain.domain.tld-error.log;
ssl_certificate /etc/letsencrypt/live/subdomain.domain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/subdomain.domain.tld/privkey.pem;
## This should be in your http block and if it is, it's not needed here.
index index.php;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ \.php$ {
#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
include fastcgi_params;
fastcgi_intercept_errors on;
#fastcgi_pass php;
#The following parameter can be also included in fastcgi_params file
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
}

Laravel nova not working with nginx+php-fpm, this.app is undefined after redirect to login

When I install it on the server - it doesn't work, i got blank screen with background and this.app is undefined error in console on server/nova/login page.
nginx config:
server {
listen 80;
listen [::]:80;
server_name wtw.test.loc;
root /home/test/sites/wtw/www/public;
access_log /home/test/sites/wtw/logs/access.log combined;
error_log /home/test/sites/wtw/logs/error.log warn;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ /\.(?!well-known).* {
deny all;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.1-wtw.test.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}

multiple wordpress in one server with nginx

I have one main wordpress app installed in this domain test.wa-essence.com,
now I want to setup a second wordpress under a subdomain test.wa-essence.com/wachampionacademy
the first wordpress in located inside /var/www/test_wa_essence
and the second wordpress is inside /var/www/wa_champion
I followed this instruction on setting the nginx https://serversforhackers.com/c/nginx-php-in-subdirectory
and here is the nginx config that I have written
server {
root /var/www/test_wa_essence;
index index.php index.html index.htm index.nginx-debian.html;
server_name test.wa-essence.com;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location /wachampionacademy {
alias /var/www/wa_champion;
try_files $uri $uri/ #nested;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location #nested {
rewrite /wachampionacademy/(.*)$ /wachampionacademy/index.php?/$1 last;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/test.wa-essence.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/test.wa-essence.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 = test.wa-essence.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name test.wa-essence.com;
return 404; # managed by Certbot
}
I managed to install both wordpress by using different nginx config.
the first app can be accessed without any problem, however, test.wa-essence.com/wachampionacademy return me 404 eventhough it appears to be at the right wordpress app.
Please tell me what I got wrong in my nginx setup. Thanks
server {
root /var/www/wa_essence;
index index.php index.html index.htm index.nginx-debian.html;
server_name test.wa-essence.com;
location /wachampionacademy/{
try_files $uri $uri/ /wachampionacademy/?$args;
}
location / {
# try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
}
server {
listen 80;
server_name test.wa-essence.com;
}
that is the final nginx config that I used,
however, the most important thing that I change I believe is the wordpress siteurl and homeurl to test.wa-essence.com/wachampionacademy

Nginx downloads php file instead executing

I get to load root domain and categories or pages. But I can't login to /admin/ or /phpmyadmin/ but instead it downloads application/octet-stream file.
What can be done? Thanks
Here's my conf file:
server {
listen 80;
listen [::]:80; #Use this to enable IPv6
server_name localhost;
root /var/www/html/;
index index.php;
location / {
try_files $uri $uri/ #rewriteapp; }
location #rewriteapp {
# rewrite all to index.php
rewrite ^(.*)$ /index.php/$1 last; }
# Php configuration location ~ ^/(index|index_dev)\.php(/|$) {
# Php-FPM Config (Socks or Network)
fastcgi_pass unix:/run/php/php7.1-fpm.sock;
# fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
# Security. discard all files and folders starting with a "." location ~ /\. {
deny all;
access_log off;
log_not_found off; }
# Stuffs location = /favicon.ico {
allow all;
access_log off;
log_not_found off; } location ~ /robots.txt {
allow all;
access_log off;
log_not_found off; }
# Static files location ~* ^.+\.(jpg|jpeg|gif|css|png|js|pdf|zip)$ {
expires 30d;
access_log off;
log_not_found off; }
}
i had a similar problem with
location = /images/favicons/site.webmanifest {
log_not_found off;
access_log off;
}
it download the file instead of display only
edit:
i found a solution that work, but don't know if the best...
location = /images/favicons/site.webmanifest {
default_type webmanifest;
log_not_found off;
access_log off;
}

How to setup nginx with opencart 1.5.5?

It is possible to use nginx with OpenCart? I am using following nginx zone:
server {
listen 80;
listen [::]:80;
root /home/username/Development/shop.local;
index index.php;
server_name shop.local;
location /image/data {
autoindex on;
}
location /admin {
index index.php;
}
location / {
try_files $uri #opencart;
}
location #opencart {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
deny all;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
But when i visit shop.local i am getting redirecto to shop.local/install/index.php and nginx throws me an error 404. What's wrong with my config?
Try this one:
# FORCE WWW
server {
server_name site.com;
rewrite ^(.*) http://www.domain.com$1 permanent;
}
# MAIN SERVER
server {
server_name www.domain.com;
listen 80;
root /var/www/www.domain.com/public;
index index.php index.html;
location /image/data {
autoindex on;
}
location /admin {
index index.php;
}
location / {
try_files $uri #opencart;
}
location #opencart {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
deny all;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires max;
log_not_found off;
}
location ~ \.php$ {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}

Categories