Django and wordpress on nginx 404 error - django

I have a django running on example.com, i need add a Wordpress to my server, would be example.com/blog, perhaps doesnt work (404 error):
listen 80;
server_name www.example.com;
location ^~ /blog/ {
root /www/blog;
index index.html index.htm index.php;
try_files $uri =404;
location ~ \.php {
root /www/blog;
fastcgi_split_path_info ^(.*\.php)(.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
}
}
location / {
uwsgi_pass unix:/tmp/myapp.sock;
include /www/webapp/system/uwsgi_params; # the uwsgi_params file you installed
uwsgi_read_timeout 300;
}

I ran in this problem too. Here, you can check my location config.
location /blog {
root /var/www/html;
try_files $uri $uri/ /blog/index.php?$args;
index index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}
Adapted for your config:
location /blog {
root /www/blog;
try_files $uri $uri/ index.php?$args;
index index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}

#Levi configuration give me some light, i need to modify because i'm getting 404 error or No input file especified.
location /blog {
alias /www/blog;
try_files $uri $uri/ index.php?$args;
index index.php;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /www/blog$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
}
}

Related

What is equivalent to conatiner name in docker-composer to aws

I have project which uses nginx and php-fpm container.
In docker-compose, I can use this nginx setting fastcgi_pass php:9000;
(php is container name of php-fpm)
in nginx.conf
server {
listen 80;
server_name xxx.example.com;
index index.php index.html index.htm;
root /var/www/public;
client_max_body_size 200M; # 413 Request Entity Too Large
location / {
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
#fastcgi_pass 0.0.0.0:9000;
#fastcgi_pass unix:/var/run/php-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
However now I want to use set(nginx, php-fpm in ECS.
In Ecs there is not container name.
And php-fpm container accept only
netstat -an|grep LISTEN
tcp6 0 0 :::9000 :::* LISTEN
Now, I tried few patterns in nginx.conf
fastcgi_pass php:9000;
#fastcgi_pass 0.0.0.0:9000;
#fastcgi_pass unix:/var/run/php-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
but either one doesn't work.
How can I set?

Setup Bitnami Nginx for subdomain

My domain is on AWS server with Bitnami Nginx installation. My goal is to create a subdomain for the test laravel application. Is this the correct bitnami.conf setting?
domain with certificates https://example.com
subdomain without certificates http://dev.example.com
/opt/bitnami/nginx/conf/bitnami/bitnami.conf:
#Rewrite any http requests for (www)example.com to https version.
server {
server_name www.example.com example.com;
return 301 https://example.com$request_uri;
}
#redirect block
server {
listen 443;
ssl_certificate "/etc/lego/certificates/example.com.crt";
ssl_certificate_key "/etc/lego/certificates/example.com.key";
server_name www.example.com;
return 301 https://example.com$request_uri;
}
#The example.com SSL website, main processing block
server {
listen 443 ssl;
ssl_certificate "/etc/lego/certificates/example.com.crt";
ssl_certificate_key "/etc/lego/certificates/example.com.key";
server_name example.com;
root /opt/bitnami/nginx/html/example.com/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 300;
fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
server {
listen 80;
server_name dev.example.com
root /opt/bitnami/nginx/html/dev.example.com/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 300;
fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}

Nginx remove '?' symbol before extension

I managed to make my index.php script to run properly when I get a url like:
http://myserver.com/?something.m3u8
Still, I need to remove the ? from it.
Any ideas?
My Nginx config looks like:
server {
listen 6868 default_server;
root /var/tmp/mfl;
index index.php;
# Make site accessible from http://localhost/
server_name localhost;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.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;
}
Apparently is was an one line solution
location / {
try_files $uri $uri/ /index.php?$args; #appended this line
}

Django Double Slash in URLS Issue (Multiple Webservers, Apache and Nginx)

To see an example: load up a example.com, click on a link that's linking to /test and instead of going to http:// example.com/test/ it goes to http:// www.example.net//test/
Or if you login, the login form for the auto-generated django admin section posts to //admin instead of admin.
Seems like this is a django issue, but the only thing I changed was nginx.
Couple of additional notes (added Oct 31):
This problem seems remarkably similar to https://serverfault.com/questions/134863/nginx-fastcgi-problems-with-django-double-slashes-in-url but the difference is that I'm getting slashes added before the project root "//admin/" vs. "admin//". The successful solution there hasn't helped me.
I'm using the current SVN version of Django.
Here is the nginx fastcgi_conf:
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;
Django project config
server {
listen 80;
server_name www.site.net;
location / {
fastcgi_pass unix:/path/to/site/server.sock;
include fastcgi.conf;
access_log /var/log/nginx_django.log main;
}
location ^~ /admin/$ {
fastcgi_pass unix:/path/to/site/server.sock;
include fastcgi.conf;
access_log /var/log/nginx_django.log main;
}
location ~* ^.+\.(mpg|avi|mp3|swf|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|txt|tar|mid|midi|wav|rtf|mpeg))
$ {
root /path/to/site/media;
limit_rate 2000K;
access_log /var/log/nginx_django_media.log download;
access_log off;
}
location ^~ /static/ {
root /path/to/site;
access_log /var/log/nginx_django_static.log download;
expires 30d;
}
location /403.html {
root /opt/nginx;
access_log off;
}
location /401.html {
root /opt/nginx;
access_log off;
}
location /404.html {
root /opt/nginx;
access_log off;
}
location = /_.gif {
empty_gif;
access_log off;
}
}
fastcgi_param SCRIPT_NAME '';
This solve the // problem for me.

Django and Nginx try_files 403 for site root page

I use such Nginx configuration for the domain:
server_name_in_redirect off;
listen 80;
server_name ~^(www\.)?(.+)$;
root /var/www/$2/htdocs;
location / {
try_files $uri $uri/ $uri/index.htm #django;
index index.html index.htm;
}
location #django {
fastcgi_pass 127.0.0.1:8801;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param SERVER_NAME $server_name;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
fastcgi_param REMOTE_ADDR $remote_addr;
}
Django URL config:
urlpatterns = patterns('',
url(r'^$', home, name='home'),
url(r'index.htm', home, name='home'),
url(r'^(?P<name>.*).htm$', plain_page, name="plain_page"),
}
all urls like http://domain.com/somepage.htm works good, except http://domain.com/ it always shows 403 by Nginx.
if you add static index.htm file to the site root - it's opened because of try_files directive
if you have no static index.htm, but call http://domain.com/index.htm page is opened by django
buf it you have no static index.htm and open http://domain.com/ you get no page, but by idea
index.htm should be looked and passed to the django as the last in the try_files chain.
how to make http://domain.com/ work (should call django's index.htm) in this case?
Add this
location = / {
rewrite ^(.*)$ /index.htm last;
}
underneath the root line to do a rewrite of the URI before further processing.
PS. You have probably sorted this out during the year since your asked, but here it is for other to see.
A better solution is you provide a / url in your urls.py is remove the
root /var/www/$2/htdocs;
Then only include the root in location {} blocks where you serve up static assets.