So, i have a html landing page with some php code and django project. Want to make like this: site.com = **landing page ** site.com/dashboard = django project.
what i´ve already did?
create simple index.html in /var/www/html
changed /etc/nginx/sites-available/default
server {
listen 8001 default_server;
listen [::]:8001 default_server ipv6only=on;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:8001;
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-Proto $scheme;
}
location ~ /lp/.*\.php$ {
root /var/www/html;
index index.php index.html index.htm;
set $php_root /var/www/html/;
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 /lp {
root /var/www/html;
index index.php index.html index.htm;
set $php_root /var/www/html/;
try_files $uri $uri/ /index.php;
}
}
Thanks for any help
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Sign up for Infrastructure as a Newsletter.
Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
@arsaevm
Looking at the configuration you provided, you’re setting the server block to listen in on Port 8001 and then proxying all requests to / to port 8001 which is redundant.
Breakdown
The second line reading:
listen 8001 default_server;
says that:
server_name localhost;
should be listening to port 8001 for connection attempts, while
proxy_pass http://127.0.0.1:8001;
says that all connections to
/
should be proxied to port 8001 even though requests to port 8001 should already be getting handled.What Changes Are Needed?
You really only need to proxy requests to your Django application since it’s what should be running on another port.
Your original post says that you want site.com to be the landing page and site.com/dashboard to be where requests for the Django project are handled, correct? If so, let’s get started :-).
We’ll be starting with a blank canvas and building it up, so here’s our blank canvas:
Let’s start by listening in on Port 80, the standard HTTP port.
Change
server_name localhost;
to use your actual domain name; if your domain is example.com, then:Directly below
server_name
, define your root path using:Now we need to setup our base location block, i.e. /.
Now, from your first post, I’m not sure if you’re wanting PHP to only be handled from specific location such as /lp/ or if you want PHP to be served from any location that isn’t /dashboard. For the purpose of getting you setup, I’m going to run with running PHP anywhere a valid request is made.
So we need to setup our PHP block. What this does is simply take care of requests for PHP files. You need to make sure that your PHP-FPM configuration is using sockets instead of TCP though (as long as you’ve not modified the configuration, sockets are the defaults).
Now we need to handle requests to /dashboard, which is where you’ve said your Django app will reside. Using the default port of 8001, this is where we proxy requests to the port Django is listening on.
Hopefully that’ll help get you up and running.