I'm building a website in Laravel 5.2 and rather than building a forum from scratch, I wish to install one such as SMF.
Laravel is currently in the root directory of my web server and I wish to keep it there as I wish to install SMF in a folder.
For example: www.example.com/smf
I'm thinking to install it in Laravel's /public folder but I'm afraid they will they conflict with each other. Is the /publicfolder the correct place to install SMF and should I use a route to point to the SMF folder?
Server: D.O droplet via Laravel Forge
You need to add custom rules for the folder(s) you want to use before Laravel related rules:
location /smf/index.php(/.*)?$ {
fastcgi_split_path_info ^(/smf/index.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_read_timeout 1000;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
location /smf/ {
if (!-e $request_filename) {
rewrite ^.*$ /smf/index.php last;
}
try_files $uri $uri/ smf/index.php?args;
}
Please look for sample nginx config file here.
You could use Nginx to redirect www.example.com/smf to your SMF installation. To do so add this to your server block:
location /smf {
# nginx will concatenate the string above with the root value
# so your SMF files should be in "/path/to/smf/parent/dir/smf".
# Make sure that Nginx can access them.
root "/path/to/smf/parent/dir";
# change this config to suit your needs
index index.php index.html index.htm;
location ~ \.php$ {
# Here use the same config from the server block that allows you
# to execute PHP scripts
fastcgi_pass 127.0.0.1:9123;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
A couple of things I should add:
Backup the config file before editing them.
Although I've tried the code above (and it works on my machineā¢) I must say that I'm not an Nginx expert.
Related
I am currently trying to implement a wordpress on a sub-domain using nginx.
I've installed all the dependencies (php 7.2, mariadb, mysql) and configured it all.
When I try to access to the website, here is what I got :
To be more explicit: here's what I did to configure nginx in order to use wordpress:
sudo nano /etc/nginx/conf.d/location.conf
server{
server_name subdomain.domain.fr;
root /home/domain/wordpress/;
location / {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
include fastcgi_params;
index index.php index.html index.htm;
try_files $uri $uri/ =404;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
}
My problem is that when I first use a wordpress website, I'm used to see some CSS on the page. When I inspect this page, I can see that the css files are included, but not used. I dont understand why. I think I have a privilege issue or anything else, but it's my first time using nginx with wordpress so I must have done something wrong:
Thanks for your help
I've found a solution that works perfectly:
adding this solved all my problems :
location ~* \.(?:css|js|map|jpe?g|gif|png)$ { }
Thanks for your help
I have two docker-containers: nginx and php-fpm.
I want to make them self-contained (containers will clone repo from git on build) for production. But after cloning repo I need to make some initial stuff, like composer install in project folder. I can do it inside php-fpm container, because I have php there. But how to prepare code in nginx container? I don't have php there for composer.
Everything is fine, when I mount same initialized folder into both containers.
Maybe I'm doing something wrong, what is best way to do self-contained container for nginx+php-fpm?
For now I have this nginx-config:
server {
listen 80;
server_name localhost;
index index.php index.html;
# I need only /api/ path
location /api/ {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
root /var/www/public;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass api:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
You should only have the PHP files on the FPM server. As you previously noted, you should have php cli to run composer on that server. You shouldn't need any PHP files on the nginx server. SCRIPT_FILENAME will be resolved by the CGI server so that location does not need to exist on the web proxy. If you need to make config changes to the nginx server, you probably want to use something more system oriented like Salt, Chef or Puppet.
location ~ \.php$ {
# This is the webserver root for static junk
root /var/www/public;
...
# Point this somewhere else if the docroot is in a different location on the FPM server.
fastcgi_param SCRIPT_FILENAME /home/php-fpm/wwwroot/$fastcgi_script_name;
}
I installed CodeIgniter 3 after a long time on PHP-fpm and nginx (Ubuntu). Previously I had always used CodeIgniter on Windows and configuring it on Windows and Apache it was a piece of cake.
Now I wanna install it on nginx, because I wanna use nginx-push-stream-module, which isn't possible from apache.
Now when I'm configuring it, its not working.
If I type localhost/myexample.com or localhost/myexample.com/index.php it works (myexample.com is the name of that directory)
but when I try to access
localhost/myexample.com/welcome
or
localhost/myexample.com/welcome/index
or
localhost/myexample.com/index.php/welcome
or
localhost/myexample.com/index.php/welcome/index
it doesn't work in any of the 4 cases (with or without index.php)
My root directory is /var/www/html/myexample.com
I tried all of the rewrite settings available online (including the following settings) from different blog posts etc (as I'm not used to nginx myself)
server {
server_name myexample.com;
root /var/www/html/myexample.com/;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php;
}
location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
expires 15d;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html/myexample.com/index.php;
fastcgi_param REQUEST_URI $request_uri;
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_pass unix:/var/run/php/php7.0-fpm.sock;
}
}
Edit: I also tried the method mentioned at Nginx's official website, but that's also not working.
You should modify your /etc/hosts and add this line:
127.0.0.1 myexample.com
And after that use myexample.com or myexample.com/welcome to access your CodeIgniter site
First - confirm what the server name is going to be. Set that in the your hosts file, then confirm the web root.
So in /etc/hosts add
127.0.0.1 myexample.com
Then your index.php file should be in
/var/www/html/myexample.com/
You should get CI up and working on the url
http://myexample.com
I am using Symfony2 (PHP) framework for my project and is having a small problem with regards to configuring my NGINX to catch request going to a 3rd party library I placed under "web" directory.
This is my configuration
server {
listen 80;
server_name test.com;
root /var/www/my-symfony-project/web;
rewrite ^/app\.php/?(.*)$ /$1 permanent;
location / {
index app.php;
try_files $uri #rewriteapp;
}
location #rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
As you may have noticed that the root is pointed in "/var/www/my-symfony-project/web" directory.
Now, the problem is that I have this "some-plugin" folder inside the "web" directory and there are PHP files from there that are not handled by the Symfony2 routing.
I actually made it work when I have the following "location" block inside the "server" block illustrated above.
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
}
It seems okay having this type of configuration at first but we realized that it accepts request to any "*.php" file to which we evaluated as a security breach.
Any suggestions?
Allowing access to .php files is usually not considered dangerous or a security breach, as long as the PHP files are executed and not served in their source form and, of course, don't print any sensitive information.
If either of the former are not the case, you should probably change your setup or your code.
Anyway, you should be able to restrict the .php file handling to /var/www/my-symfony-project/web/some-plugin by using the following as location:
location ~ ^/var/www/my-symfony-project/web/some-plugin/.*\.php$ {
# your rules here
}
This should match all files whose path starts with /var/www/my-symfony-project/web/some-plugin/ and end with .php in upper or lower case.
I try to run a simple Symfony2 application on a virtual machine. I have Nginx on this VM (generated with PuPHPet and Vagrant), but there's a problem.
When I try to access to the demo route /demo (local.dev/Symfony/web/app_dev.php/demo), Nginx force me to download a file. It seems it works the same way when I specify a random route.
I don't know how to solve this problem, I searched while 2 days for a specific configuration of Nginx but I found nothing. Here is my config file for this Symfony app :
server {
server_name test.dev;
root /var/www/local.dev/Symfony/web;
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
error_log /var/log/nginx/sf-error.log;
access_log /var/log/nginx/sf-access.log;
}
Thanks for your help.