I have problem with my configuration server on nginx.
My configuration:
server {
listen 80;
server_name shop.md;
index index.php index.html index.htm;
access_log /var/log/nginx/test.dev.access.log;
error_log /var/log/nginx/test.dev.error.log;
location / {
root /home/vagrant/Workspace/shop/web;
try_files $uri $uri/ app_dev.php /app_dev.php$is_args$args;
}
location ~ .php$ {
root /home/vagrant/Workspace/shop/web;
index index.html index.htm index.php;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_param APPLICATION_ENV development;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
sendfile off;
}
This configuration allow urls like this :
http://shop.md:8000/1/femei-pantofi
http://shop.md:8000/1/femei-pantofi?min_price=1&max_price=1000
For this URL:
http://shop.md:8000
I get the error 403 Forbidden
I use the #rewriteapp directive of nginx for my Symfony2 projects. The resulting configuration looks somewhat like this:
# strip app.php/ prefix if it is present
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location / {
index app.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
# pass the PHP scripts to FastCGI server from upstream phpfcgi
location ~ ^/(app|app_dev|adminer)\.php(/|$) {
fastcgi_pass phpfcgi-siyabonga;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
}
This works fairly well for me and is taken from the official nginx wiki page about Symfony2 with some additional changes. Also you should check the official Symfony2 docs. They have an example of a correct nginx configuration.
Related
I want to create dockerized Wordpress with nginx that will use /kokpit instead of /wp-admin I'm using nginx:latest container with default config. And declared my server block for Wordpress like below
server {
listen 443 ssl;
ssl_certificate /etc/nginx/localhost.crt;
ssl_certificate_key /etc/nginx/localhost.key;
server_name dimidia.dev.com;
root /var/www/html;
index index.php;
error_log /var/log/nginx/stderr_dimidia debug;
access_log /var/log/nginx/stdout_dimidia;
location /media
{
rewrite ^/media/(.+) /wp-content/themes/mytheme/$1;
}
location /
{
try_files $uri $uri/ /index.php?$args;
}
location /kokpit
{
rewrite ^/kokpit(.*) /wp-admin$1;
}
location ~ \.php$ {
fastcgi_read_timeout 300;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
client_max_body_size 50m;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
fastcgi_pass dimidia_php: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 when I reach to /kokpit files like load-scripts.php are returning 404 instead of scripts, and I cannot reach any php files inside kokpit (all are returning 404) big question is: why?
I want to use Baikal on my server together with NGINX. The index.php of baikal is in /baikal/html
The request for the following configuration works with this url:
https://www.mydomain.com:8001/baikal/html
How can I change the NGINX configuration that
https://www.mydomain.com:8001/baikal
gets redirected to https://www.mydomain.com:8001/baikal/html?
Here is my NGINX configuration:
server {
listen 8001;
ssl on; # <-------------------------------------------- SSL
ssl_certificate /etc/nginx/ssl/seahub.crt; # <--------- SSL
ssl_certificate_key /etc/nginx/ssl/seahub.key; # <----- SSL
server_name confile.no-ip.biz; #.tld; # <----------------- CHANGE THIS
root /usr/share/nginx/www;
index index.html index.htm index.php;
rewrite ^/.well-known/caldav /cal.php redirect;
rewrite ^/.well-known/carddav /card.php redirect;
location / {
location ~ ^(.+\.php)(.*) {
try_files $fastcgi_script_name =404;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
include fastcgi_params;
}
charset utf-8;
location ~ /(\.ht|Core|Specific) {
deny all;
return 404;
}
}
}
First of all, you should not have a location inside of another location. Make sure they're all seperate.
Next, to actually create the rewrite:
location = /baikal {
return 301 /baikal/html
}
should do the trick.
(first at all, sorry for english it's not my native :/ )
I have a problem with my NGINX conf, I have 2 symfony2 projects in 2 folders. The first one is my root dir (www.mywebsite.com/) in my nginx conf and I would have the second like this www.mywebsite.com/secondwebsite.
The first website works fine on port 80 (with classic nginx config).
My second website works fine on the port 82 (www.mywebsite.com:82) for example with this conf :
server {
listen 82;
server_name mywebsite.com *.mywebsite.;
root /var/www/project/dev/secondwebsite/web/;
index app_dev.php;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app_dev.php$is_args$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
include fastcgi_params;
add_header Access-Control-Allow-Origin *;
}
}
But I get a problem when I try to access like this www.mywebsite.com/secondwebsite, all my symfony2 routes does not work (I get a 404 on each), I put my app_dev.php as index to get more details
Here is the conf of my nginx conf :
server {
listen 80;
server_name mywebsite.com *.mywebsite.com;
index app.php;
root /var/www/project/dev/mywebsite/web;
error_log /var/log/nginx/mywebsite.error.log;
access_log /var/log/nginx/mywebsite.access.log;
if ($http_host != "www.mywebsite.com"){
rewrite ^ http://www.mywebsite.com$request_uri permanent;
}
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location /secondwebsite/ {
alias /var/www/project/dev/secondwebsite/web/;
index app_dev.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index app_dev.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
add_header Access-Control-Allow-Origin *;
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
include fastcgi_params;
add_header Access-Control-Allow-Origin *;
}
}
I've search many times but nothing works, I really need help ^^
I've got problem with my project in symfony2 when i'm trying to run this on nginx.
www.domain/ works fine
www.domain/app_dev.php ,"An error occurred while loading the web debug toolbar (404: Not Found).Do you want to open the profiler?"
www.domain/app.php/someurl/ - 404 not found
Is it server configuration issue or should I change my .htaccess in some way to make it possible to run with nginx?
You can check my dev config (with PHP-FPM):
server {
listen 80;
server_name dev.example.com;
root /var/www/web;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log error;
index app.php index.html index.htm;
try_files $uri $uri/ #rewrite;
location #rewrite {
rewrite ^/(.*)$ /app.php/$1;
}
location ~ \.php(/|$) {
# try_files $uri =404;
fastcgi_index app.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_buffer_size 1280k;
fastcgi_buffers 4 2560k;
fastcgi_busy_buffers_size 2560k;
}
location ~ /\.ht {
deny all;
}
}
I have nginx set up for Rails application that has been working beautifully for me. Now I want to move my Wordpress blog from blog.website.com to website.com/blog, so web crawlers treat it as part of the site.
I created a symbolic link in my Rails app's public/ directory and added the following to my nginx configuration:
# Rails server
server {
root /project/path/current/public;
server_name project.com;
passenger_enabled on;
rails_env production;
client_max_body_size 20m;
if ($http_x_forwarded_proto != 'https') {
return 301 https://$host$request_uri;
}
location /blog {
index index.html index.php;
try_files $uri $uri/ /blog/index.php?q=$uri&$args;
if (!-e $request_filename) {
rewrite ^.+?(/blog/.*.php)$ $1 last;
rewrite ^ /blog/index.php last;
}
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
This works great.
But what I'd like to do is skip the symbolic link part. I'd like nginx to route directly to the wordpress directory. I tried changing the /blog block to:
location ^~ /blog {
root /home/ubuntu/apps/blog;
index index.html index.php;
try_files $uri $uri/ /blog/index.php?q=$uri&$args;
if (!-e $request_filename) {
rewrite ^.+?(/blog/.*.php)$ $1 last;
rewrite ^ /blog/index.php last;
}
}
This works, as in I'm being correctly redirected to the wordpress folder but my server doesn't know what to do with php files and sends them to my browser as files to download.
I tried nesting the \.php$ location inside the /blog location but it results in 404 error.
What's wrong with the following piece and how to fix it?
location ^~ /blog {
root /home/ubuntu/apps/blog;
index index.html index.php;
try_files $uri $uri/ /blog/index.php?q=$uri&$args;
if (!-e $request_filename) {
rewrite ^.+?(/blog/.*.php)$ $1 last;
rewrite ^ /blog/index.php last;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
I haven't fixed the snippet from the question but I managed to solve the problem with nginx configuration without using a symbolic link by using two server blocks.
server {
location / {
proxy_pass http://localhost:82/;
}
location /blog {
root /var/proj/blog/current;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
}
# Rails server
server {
listen 82;
root /var/proj/site/current/public;
server_name site.com;
passenger_enabled on;
rails_env staging;
client_max_body_size 20m;
# other configuration
}