Nginx vhost website + wordpress alias in subfolder - wordpress

I want to create a vhost for a php website in this folder:
/var/www/mydomain.com/home
and an alias for this folder for a wordpress blog:
/var/www/mydomain.com/public_html
I try this vhost:
server {
listen 80;
root /var/www/mydomain.com/home;
index index.php index.html index.htm;
charset UTF-8;
server_name mydomain.com;
access_log /var/log/nginx/mydomain.com.access.log;
error_log /var/log/nginx/mydomain.com.error.log debug;
location /blog {
alias /var/www/mydomain.com/public_html;
try_files $uri $uri/ /index.php?$args =404;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
With this configuration, my website work fine, the homepage of my blog is OK, static files are OK, the page like http://mydomain.com/blog/wp-login.php are OK, all the admin panel is OK :
http://mydomain.com/blog/wp-admin/
(wp-admin folder exist)
But the page in front of like
http://mydomain.com/blog/terms-and-conditions/
http://mydomain.com/blog/contact/
or all the page with / like blog/.../... always go to my /var/www/mydomain.com/home/index.php
What did I forget to do?

Related

Trying to serve wordpress in a subdirectory using NGINX webserver but failing

I have a react website which I am serving using NGINX. I wanted to create a blog for the same. So I tried to use wordpress in a sub-directory.
`
server {
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name domain.com;
location / {
try_files $uri $uri/ =404;
}
location ^~ /blog {
client_max_body_size 10m;
if (!-f $request_filename) {
rewrite [^/]$ $uri/ permanent;
}
try_files $uri $uri/ /index.php?$args;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^/wordpress(/.+\.php)(.*)$;
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
}
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
#ssl certificates here
}
`
After hours of reading docs, blogs and stack I got my homepage set up. However all my pages on the blog are returning 404. I am attaching my nginx config.
My directory structure is
/var/www/html/ : root folder for my react website
/var/www/html/blog : root folder for my wordpress ( no /wordpress subfolder present)
Add this lines
location /blog {
try_files $uri $uri/ /blog/index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(/blog
}

Nginx Wordpress with magento 1.9

I am currently trying to move our sites from apache and subdomains to nginx and the removal of subdomains.
Currently my folder structure has wordpress as the main directory and the shops living in a folder called shops.
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/test.local;
index index.html index.htm index.php;
server_name test.local;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location /proshop {
alias /var/www/test.local/shops;
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 /proshop/(.*)$ /shops/index.php?/$1 last;
}
location /shop {
alias /var/www/test.local/shops;
try_files $uri $uri/ #shop;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
location #shop {
rewrite /shop/(.*)$ /shops/index.php?/$1 last;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}
}
The problem i am facing is:
domain.com/proshop/ shows me my homepage allbeit with broken styling and js.....
however if i try
domain.com/proshop/admin
to get to the admin area i am hitting a 404?

phpMyAdmin 404 error on Digital Ocean hosting

I'm getting a 404 error after install phpMyAdmin using Digital Ocean's guide. I have multiple domains setup on Ubuntu running nginx. There is a phpmyadmin directory within /var/www/. The only difference from the guide was the following command:
sudo ln -s /usr/share/phpmyadmin/ /var/www
Do I need to add server block possibly? Since I have multiple domains, each of them has a separate configuration file.
Sample config file:
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/domain1.com/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name MY_IP_ADDRESS;
location / {
try_files $uri $uri/ =404;
}
location /phpmyadmin {
root /var/www/;
index index.php index.html;
}
location ~ \.php$ {
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;
try_files $uri /index.php;
}
location ~ /\.ht {
deny all;
}
}
I'm not great at server administration. Any suggestions?
Define this server block it worked for me.
A basic configuration for phpmyadmin in you case.As you have created a symbolic link in /var/www.
sudo ln -s /usr/share/phpmyadmin/ /var/www
server {
listen 80;
server_name website.in www.website.in;
autoindex on;
location /phpmyadmin {
root /var/www/;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
try_files $uri $uri/ /index.php;
}
}
location / {
root /var/www/your/path;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
try_files $uri $uri/ /index.php;
}
}
}

nginx loading assets but not showing for wordpress app

I am using the following setup to run 2 applications on the same domain. If the first application returns 404 it tries the other one (wordpress on /blog).
location /blog {
root /var/www/blog;
index index.html index.htm index.php;
try_files $uri $uri/ /blog/index.php?$args;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
location / {
# ...
proxy_intercept_errors on;
recursive_error_pages on;
error_page 404 =200 /blog/$uri;
}
Every page loads as expected and assets return 200 and the correct content.
But css and most images of those assets are not applied to the page, while a few work just fine.
The following is included:
include /etc/nginx/mime.types;
I understand that this is probably a bad configuration anyway but in my understanding it should still work.
Is there another configuration to achieve something similar?
EDITED:
The wordpress installation is located in /var/www/blog/blog/
I can't exactly understand the problem but I suggest you bring out that php block outside and remove blog and $args after index.php uri.
Try this one instead, let me know if this works out. :)
location /blog {
root /var/www/blog;
index index.html index.htm index.php;
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location / {
# ...
proxy_intercept_errors on;
recursive_error_pages on;
error_page 404 =200 /blog/$uri;
}

Adding new site to Ngnix

I am really new to Nginx, and am to add a new website to a remote Nginx server.
I notice that /etc/nginx/conf.d/default.conf has been modified to this:
server {
server_name api.example.com;
root /var/www/html/api/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
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;
}
}
I want to add another url: testapi.example.com to the same server. All the tuturiols point to /etc/nginx/sites-enabled/, but that folder is empty. This is a production machine, so I would not like bring any downtime.
Please help.
You could add another server block to /etc/nginx/conf.d/default.conf for your second domain or a better way would be to create a new .conf file in /etc/nginx/conf.d/ (with a meaningful name) and in that file define a new server block for the second domain.
So you'd keep your /etc/nginx/conf.d/default.conf
server {
server_name api.example.com;
root /var/www/html/api/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
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;
}
}
And add /etc/nginx/conf.d/testapi.conf
server {
server_name testapi.example.com;
root /var/www/html/testapi/root;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
... rest of config for second domain...
}

Resources