Wordpress Nginx proxy cannot load wp-admin/ajax.php - ajax

My website is hosted on 6-cylinder.com
and I decided to add a wordpress blog which is in a completely different VPS. So, I used proxy to list my blog as a subdirectory of my main domain
So the final product should be 6-cylinder.com/blog
The proxy is working completely fine except for one file only!!!!!
wp-admin/ajax.php
This is the error message in chrome console
Here is what I added to my wp-config.php
$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/", $_SERVER['REQUEST_URI']);
define( 'WP_SITEURL', 'http://6-cylinder.com/blog' );
define( 'WP_HOME', 'http://6-cylinder.com/blog' );
and here is the proxy code in the nginx file
location ^~ /blog/ {
proxy_pass http://139.59.211.216/;
proxy_set_header X-Original-Host $host;
proxy_set_header X-Is-Reverse-Proxy "true";
proxy_pass_header Set-Cookie;
proxy_cookie_path / /blog/;
}

The time i had problems with wp-admin the solution was to add the folowing line to the wp-config.php:
$_SERVER['HTTP_HOST']=$_SERVER['HTTP_X_FORWARDED_HOST'];
(wordpress behind nginx proxy (acces from two sources))

Related

Devilbox (docker) + Laravel Websockets

Trying to get the two to work together. Is there something I'm missing or way to debug why it's not working?
Edited .devilbox/nginx.yml as suggested here although trying to contain it to path: wsapp
---
###
### Basic vHost skeleton
###
vhost: |
server {
listen __PORT____DEFAULT_VHOST__;
server_name __VHOST_NAME__ *.__VHOST_NAME__;
access_log "__ACCESS_LOG__" combined;
error_log "__ERROR_LOG__" warn;
# Reverse Proxy definition (Ensure to adjust the port, currently '8000')
location /wsapp/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://php:6001;
}
__REDIRECT__
__SSL__
__VHOST_DOCROOT__
__VHOST_RPROXY__
__PHP_FPM__
__ALIASES__
__DENIES__
__SERVER_STATUS__
# Custom directives
__CUSTOM__
}
Installed laravel-websockets and configured to use '/wsapp'
Visit the dashboard to test:
https://example.local/laravel-websockets
But console has error:
Firefox can’t establish a connection to the server at
wss://example.local:6001/wsapp/app/a558686cac00228eb003?protocol=7&client=js&version=4.3.1&flash=false.
2 pusher.min.js:8:6335 The connection to
wss://example.local:6001/wsapp/app/a558686cac00228eb003?protocol=7&client=js&version=4.3.1&flash=false
was interrupted while the page was loading. pusher.min.js:8:6335
I've Created a Setup that works...
first you need 2 domains in devilbox...
For you Laravel App (example.local)
For you Laravel Websocket (socket.example.local)
on your socket.example.local directory...
create htdocs and .devilbox here you'll add your nginx.yml file
when you try to connect to your socket.
don't use the port anymore...
and don't isolate the socket to /wsapp anymore...
use socket.example.local in .env PUSHER_HOST value
run your laravel websocket on example.local...
visit /laravel-websockets dashboard... remove the port value then click connect
I don't suggest you'll serve your socket in /wsapp because it's hard to configure nginx to serve 2 apps... (it's hard for me, maybe someone more expert on nginx can suggest something regarding this setup)
but that's my solution... if you didn't understand, please do comment

Nginx not serving images from springboot static path

I have a springboot application that serves a page of images. These images live in a directory outside of the application in order to give certain people access to add more photos over a network share. /home/user1/share/static-images. Running this locally I am able to get things to work. But when putting this application behind nginx, I've setup the proxy_pass like this:
server {
listen 80;
listen [::]:80;
server_name www.domain.com;
location / {
proxy_pass http://localhost:8080/;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port $server_port;
}
}
This seems to work as far as it is displaying the page and any local images inside the springboot app. But none of the images from the static path are showing up. I've tried adding a path like this:
location /static-images {
root /home/user1/share/static-images;
}
But this throws a 403 forbidden message. I've new to nginx, so I'm assuming this is just an nginx configuration problem. Any clues?
please try this
location /static-images/ {
alias /home/user1/share/static-images/;
}
and reload the nginx
The requested URL path is appended to the configured root. So if someone requests http://www.example.com/static-images/img.png, the URL path is /static-images/img.png and nginx translates this to /home/user1/share/static-images/static-images/img.png in your current configuration.
Changing the root to /home/user1/share; here is probably what you want.
Sorry #slauth I am unable to verify if that works. I ended up switching to Apache and this configuration worked.
<Virtualhost *:80>
ServerName domain.com
ServerAlias www.domain.com
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</Virtualhost>

Django media file not serve in production but serving in development (localhost)?

Django media file serving in development but not on production. whatever image i am uploading through Django admin it serving on website on local host but when i live my site on digital ocean its no displaying. how to solve this issue can any one tell ? my website url-http://139.59.56.161 click on book test menu
Resurrecting a long-dead question which was all I could find to help me out here. Recording my answer for posterity. My "production" environment uses nginx as a reverse proxy in front of uwsgi hosting my django application. The solution is that Django just does not serve files in Production; instead you should configure your web-server to do that.
Django is slightly unhelpful in talking about static files and then saying 'media files: same.'
So, I believe its best to catch file requests up front, in my case in the nginx server, to reduce double-handling and also your front-end web-server is the most optimised for the job.
To do this:
within a server definition block in your /etc/nginx/sites-available/[site.conf], define the webroot, the directory on your server's file system that covers everything with the declaration 'root [dir]'.
server {
listen 80;
server_name example.com www.example.com;
root /srv/;
This next block tells nginx to send all the traffic to the uwsgi service running django - I lifted it holus bolus from an example, probably on digitalocean.com.
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Client-Verify SUCCESS;
proxy_set_header X-Client-DN $ssl_client_s_dn;
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
proxy_read_timeout 1800;
proxy_connect_timeout 1800;
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/mysite6.sock;
}
Now, here are the bits we need to serve files when they are requested. try_files attempts to serve $uri and then $uri/, and it would be a good idea to put a file like 'resource_not_found.html' in /srv and set it as the last fallback for try_files, so the user knows that this part has been unintentionally left blank.
location /static/ {
try_files $uri $uri/ ;
}
location /media/ {
try_files $uri $uri/ ;
}
}
That concludes our server block for http, hence the extra close "}".
Alternatively, you can get uwsgi doing it by setting 'static-map' or 'static-map2'. 'static-map' "eats" the mapped url part, whereas static-map2 adds it.
static-map /files=/srv/files
means a request for /files/funny.gif will serve /srv/files/files.gif.
static-map2 /files=/srv
will do the same thing, because it will take a request for /files/funny.gif and look for /srv/files/funny.gif. As per the uwsgi docs, you can create as many of these mappings as you want, even to the same uri, and they will be checked in order of appearance. Damnit, I've just now finally found the docs for nginx open source.
uwsgi docs

trouble getting a file from node.js using nginx reverse proxy

I have set up an nginx reverse proxy to node essentially using this set up reproduced below:
upstream nodejs {
server localhost:3000;
}
server {
listen 8080;
server_name localhost;
root ~/workspace/test/app;
location / {
try_files $uri $uri/ #nodejs;
}
location #nodejs {
proxy_redirect off;
proxy_http_version 1.1;
proxy_pass http://nodejs;
proxy_set_header Host $host ;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Now all my AJAX POST requests travel just fine to the node with this set up, but I am polling for files afterward that I cannot find when I make a clientside AJAX GET request to the node server (via this nginx proxy).
For example, for a clientside javascript request like .get('Users/myfile.txt') the browser will look for the file on localhost:8080 but won't find it because it's actually written to localhost:3000
http://localhost:8080/Users/myfile.txt // what the browser searches for
http://localhost:3000/Users/myfile.txt // where the file really is
How do I set up the proxy to navigate through to this file?
Okay, I got it working. The set up in the nginx.conf file posted above is just fine. This problem was never an nginx problem. The problem was in my index.js file over on the node server.
When I got nginx to serve all the static files, I commented out the following line from index.js
app.use(express.static('Users')); // please don't comment this out thank you
It took me a while to troubleshoot my way back to this as I was pretty wrapped up in understanding nginx. My thinking at the time was that if nginx is serving static files why would I need express to serve them? Without this line however, express won't serve any files at all obviously.
Now with express serving static files properly, nginx handles all static files from the web app and node handles all the files from the backend and all is good.
Thanks to Keenan Lawrence for the guidance and AR7 for the config!

Laravel+Homestead+nginx proxy: Getting the right url in my routes

I have a dedicated server with a Laravel 5 project and Homestead properly installed and working.
I just added a todo.app line in the Homestead.yml like this:
sites:
- map: todo.app
to: /home/vagrant/Code/todo-app/public
To access it from the outside, I configured an nginx reverse proxy like this:
location /todo/ {
resolver 127.0.0.1;
proxy_pass http://todo.app:8000/;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Then, I added a line in the hosts file resolving todo.app to 127.0.0.1 and installed dnsmasq as resolver for nginx.
If I browse http://dev.mydomain.com/todo, I get everything working properly except for my routes: every URL the framework will generate will forget the subdirectory. For instance, the login URL is: http://dev.mydomain.com/login but should be http://dev.mydomain.com/todo/login. Changing the APP_URL in the .env file won't help.
Have you tried grouping all your routes and adding a 'todo' prefix to all?
Here is an example:
Route::group(['prefix' => 'todo'], function(){
Route::get('index','HomeController#index')->name('Homepage');
...
//The rest of the routes
}
This could be your solution if your willing to touch your code for this installation.
If you need custom behaviours on the predefined routes and are using:
Route::auth();
in your routes file, you should remove the line and create your own routes.You can use the following screenshot as a guide to see what the previous command automatically generates for you and use it to customize and create your own:
Please review: http://i.stack.imgur.com/ep9cD.png
You can use the:
php artisan route:list
command to replicate the image results in your own solution.

Resources