Linking ghost blog in my webapp subfolder - ghost-blog

I have create a web app and ghost blog. Web app is running on port 80 and ghost blog on 2368 (default for ghost).
I want to add blog page in mydomain/blog.
Can anyone help me out with this.
I am able to run the blog on port 80 using nginx but how to run it on particular route of our web app.
this is config file of nginx
server {
listen 3333;
server_name localhost;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:1337;
}
location /blog {
rewrite ^/blog(.*) /$1 break;
proxy_pass http://127.0.0.1:2368;
}
}
My app which is hosted on port 1337 is working fine on 3333 nginx link
but when i am opening localhost:3333/blog then blog is not coming properly. it text is coming but its totally distorted seems link css is missing.
So I have two issues regarding this
1. How to host blog properly on mydomain/blog which is localhost:3333/blog in this case.
2. When i am trying to open any page (in spite of its looking distorted) then since that particular route is not found in our main app hence it redirects them to home page?

what you are looking for is hosting Ghost in a subdirectory. This link describes what steps you need to take to make that work: https://www.allaboutghost.com/how-to-install-ghost-in-a-subdirectory/.
Let me know if it worked :).

I have finally able to run it so i am going to answer it here
Lets suppose i have a app and a blog. I have run the app on example.com and blog on example.com/blog
1. App related setting
Lets say you app is running on port 1337.
2. Install ghost properly
a. you can use this link to install ghost.
b. change url of config file of ghost to http://example.com/blog
c. restart the ghost.
npm start --production
or
NODE_ENV=production forever start index.js
3 Install nginx properly
a. you can use this link to install nginx.
b. now create example.conf file in /etc/nginx/site-enabled folder.
server {
listen 80;
server_name example.com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:1337;
}
location ^~ /blog {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:2368;
proxy_redirect off;
}
}
c. restart the nginx service.
sudo service nginx restart

Related

Jenkins + nginx reverse proxy on Plesk

I'm running Plesk Obsidian on my centOS server and manually installed Jenkins on it. Jenkins is up and running. It can be used by calling http://my-server.de:38080 without any problems. I also created a new subdomain in Plesk (jenkins.my-server.de), which is secured with a lets encrypt certificate.
My idea was to use the nginx reverse proxy to call Jenkins using the new subdomain: https://jenkins.my-server.de. Therefore I disabled the use of Apache in the Plesk Apache & nginx Settings for the subdomain and added the following additional nginx directives in the Plesk web interface:
location ~ / {
proxy_pass http://localhost:38080;
proxy_read_timeout 90;
proxy_redirect http://localhost:38080 https://jenkins.my-server.de;
}
The problem is, that some sites are working and on other sites I get a 404.
Calling https://jenkins.my-server.de should show me the login page, but I get a 404. Only if I enter https://jenkins.my-server.de/index in the browser, I see the login page.
Calling https://jenkins.my-server.de/manage on the other hand loads the wanted page without error. The page https://jenkins.my-server.de/configureSecurity shows a 404 again and only works if I add /index at the end.
Am I missing something in the nginx settings?
The following configuration is working for me in combination with Plesk.
location ^~ / {
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;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect http://localhost:38080 https://jenkins.my-server.de;
proxy_pass http://localhost:38080;
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off;
add_header 'X-SSH-Endpoint' 'jenkins.my-server.de:50022' always;
}

How to deploy Flask project on Plesk subdomain

I want to ask if there is a way to deploy my Flask project to a Plesk subdomain. The site is going to be created with wordpress inside Plesk. Also, i would like to have database support.
I was struggeling with a similar issue. What i did was the following:
Installed nginx
In the subdomain -> Apache & nginx Settings, make sure to disable the proxy-mode under the nginx settings
add the following to Additional nginx directives:
location / {
# Define the location of the proxy server to send the request to
proxy_pass http://127.0.0.1:5000;
# Redefine the header fields that NGINX sends to the upstream server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Define the maximum file size on file uploads
client_max_body_size 5M;
}
location /static/ {
alias /var/www/vhosts/PATH/TO/FLASK/app/static/;
}
The rest is handled by gunicorn, you can find a great tutorial here: https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvii-deployment-on-linux
hope that helps

nginx Reverse Proxy with plesk

I've already seen some answers on here and none of the solutions seem to work.
I have domain.com with a wordpress install
and a script running on domain.com:6000
I want to be able to have script.domain.com show what's on domain.com:6000
Now the other big issue is plesk. (It gets a lot of hate but the people using the website like the UI.) but here's what I've done/tried
New folder and file in /var/www/vhosts/domain.com/conf
file : vhost_nginx.conf
and what's currently in it
server {
listen 80;
server_name script.domain.com;
location / {
proxy_pass http://domain.com:6000;
}
}
Also having tried
location /script/ {
proxy_pass http://domain.com:6000/;
}
to try and have domain.com/script show something different.
Any suggestions?
Right now in PLesk 12.5 there is no way to override "location /" via plesk, because all custom conf files are added at the end of nginx's server section after default "location /" derectives.
You can create or change hosting type of your subscription to forwarding like in this answer https://serverfault.com/a/541055/154664
But in this case port will be visible in URL.
Another solution is to create your own custom virtual host in nginx in some separate config - it's actually easiest way now.
Another solution is to customize virtual hosting templates, but it's too much side effects on Plesk upgrade.
I put this in the Plesk UI under additional nginx directives and it worked for me. You can remove the if, if you are ok with http traffic. Also replace <*> accordingly. For instance:
<your-domain> = script.domain.com, <your-host> = localhost <your-port> = 6000
if ($scheme = http) {
return 301 https://<your-domain>;
}
location ~ / {
proxy_pass http://<your-host>:<your-port>;
proxy_redirect off;
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-Forwarded-Host $server_name;
}

Nginx seems to be reverting to a directory of files?

I'm trying to run Ghost on my own VPS mostly for the learning experience (and here we are).
When I SSH in and start/restart nginx my blog URL seems to show the blog I'm trying to host, but I exit and leave it alone for a while and it seems to start showing an index of files:
Index of /
HEAD
branches/
cgi-bin/
config
description
hooks/
info/
objects/
refs/
I'm not exactly sure where that directory is coming from or what's going on, despite hours of digging into the documentation.
EDIT: Here is the [url].conf file located in /etc/nginx/conf.d
server {
listen 80;
server_name [url].com;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
There's nothing in /etc/nginx/sites-available or /etc/nginx/sites-enabled.

Jenkins Url changes when going to /jenkins/configureSecurity/

I have set up nginx as a reverse proxy for our jenkins server. Nginx is using proxy_pass to the jenkins server so it should just be forwarding the requests and responses.
When I go to my.domain.com/jenkins (hitting the nginx server) the url is fine. I can click on the url for each project and the url will still look like: my.domain.com/jenkins/job/myProject/. Even going to jenkins configure is fine.
The problem:
When I click on Configure Global Security the url changes to jenkin's sever IP. This wouldn't be such an issue but the Google Login Plugin is hitting it as well and my OAuth callbacks are set to hit the nginx server.
What I've Done:
I have set the Jenkins URL in configure to be my.domain.com/jenkins
Made sure the JENKINS_ARGS have the --prefix=/jenkins
Restarted Jenkins after setting the url in the configuration.
Verified jenkins.model.JenkinsLocationConfiguration.xml has the correct location
Any ideas or suggestions would be amazing! Thank You!
The issue was nginx and the way I was redirecting.
I was using:
location /jenkins/ {
proxy_pass $scheme://ip.address.to.server:port;
}
But needed:
location /jenkins/ {
proxy_pass $scheme://ip.address.to.server:port;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Resources