Trying to get Nginx on Jelastic to play nice with nice with socialengine. There's a myriad of forum posts and other documentation but I've hit a brick wall.
Unmodified nginx.conf
#user nobody;
worker_processes 1;
error_log /var/log/nginx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
server_tokens off;
include mime.types;
default_type application/octet-stream;
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Websocket support
#upstream websocket {
# server 127.0.0.1:<PORT>;
#}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
include /etc/nginx/aliases.conf;
#location /ws {
# proxy_pass http://websocket;
# proxy_http_version 1.1;
# proxy_set_header Upgrade $http_upgrade;
# proxy_set_header Connection "Upgrade";
#}
location / {
root /var/www/webroot/ROOT;
index index.html index.htm index.php;
location ~ \.php$ {
location ~ /\. { deny all; access_log off; log_not_found off; }
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/webroot/ROOT$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /var/www/webroot/ROOT;
}
}
index index.php index.html index.htm;
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
location ~ /\. { deny all; access_log off; log_not_found off; }
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
location ~ \.php$ {
location ~ /\. { deny all; access_log off; log_not_found off; }
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/webroot$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT /var/www/webroot;
}
}
include /etc/nginx/conf.d/*.conf;
}
This is apparently what I am trying to accomplish in order for the rewrites for socialengine to work.
location / {
index index.php index.html index.htm;
if ( $request_uri ~ "/" ) {
rewrite ^(.*)$ /index.php?rewrite=1 last;
}
if (!-e $request_filename) { rewrite ^(.*)$ /index.php?rewrite=1 last;}
}
location /install/ {
index index.php;
if (!-e $request_filename) { rewrite ^(.*)$ /install/index.php?rewrite=1 last; }
}
This seems super simple to me at the outset, but for some reason any way I have attempted to add these lines(or parts thereof) has prevented the nginx server from restarting.
Related
I am trying to set the slimframework on nginx webserver. Below is my current settings. I am using the slim/slim-skeleton. Whenever I run e.g. http://myip/apiv1 it points to the index.php in /var/www/html. Even I run anything example http://myip/apiv1/token its the same as above. I tried changing the root /var/www/html/apiv1/public; to alias /var/www/html/apiv1/public; its the same. What else does nginx require any special settings.
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server_tokens off;
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/blockuseragents.rules;
limit_conn_zone $binary_remote_addr zone=addr:5m;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
#root /usr/share/nginx/html;
root /var/www/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ index.php?$query_string;
}
location /apiv1 {
root /var/www/html/apiv1/public;
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 444;
}
limit_conn addr 1;
}
I'm fairly new to Linux and I'm having a little trouble setting up my web server... I am using LEMP with Varnish and phpMyAdmin. The server is running and I can access phpMyAdmin over https etc. Now I'm trying to setup Wordpress on another directory using the include /directory/*.conf; however it doesn't seem to load the file(s). It will only load the default directory set in nginx.conf
Here's my nginx.conf,
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/v-hosts/*.conf;
index index.php index.html index.htm;
server {
listen 127.0.0.1:8080;
root /usr/share/nginx/html;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/stolenmx.com/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /srv/www/;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 443;
client_max_body_size 80M;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
}
}
And here's my file i'm trying to load for wordpress,
server {
server_name stolenmx.com;
listen 8080;
access_log /var/log/nginx/stolenmx.com-access.log;
error_log /var/log/nginx/stolenmx.com-error.log;
root /srv/www/stolenmx.com;
location / {
index index.php;
}
# Disable favicon.ico logging
location = /favicon.ico {
log_not_found off;
access_log off;
}
# Allow robots and disable logging
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Enable permalink structures
if (!-e $request_filename) {
rewrite . /index.php last;
}
# Handle php requests
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/stolenmx.com$fastcgi_script_name;
}
# Disable static content logging and set cache time to max
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
# Deny access to htaccess and htpasswd files
location ~ /\.ht {
deny all;
}
}
I have included this files directory in nginx.conf "include /etc/nginx/v-hosts/*.conf;" but for some reason it's not loading it and won't point the server_name to /srv/www/ ?
Does anyone have any suggestions as to why it won't load additional server.conf ?
I can drag the wordpress install into /usr/share/nginx/html and it works but then I can't have any more than one server. I think it's something to do with my nginx.conf but not sure what to change / add?
Regards Crafty
Before changes can affect you need to restart/reload your nginx, in CentOS it's done by running:
/etc/init.d/nginx restart
(If you are not root use sudo)
You are requiring that all your included files will be suffixed with '.conf', please make sure your file has this extension. Last thing, you configured your Wordpress server to listen on 8080, did you checked on this port?
having some issues with 'file not found' or FastCGI sent in stderr.
From what I have searched and researched about the issue it's due to the fastcgi_param SCRIPT_FILENAME not being able to locate the file. I've tried so many different combinations with the same result each time.
Here's my nginx.conf if anyone has any ideas it's much appreciated.
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 60;
include /etc/nginx/conf.d/*.conf;
index index.php index.html index.htm;
server {
listen 127.0.0.1:8080;
root /usr/share/nginx/html;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ { root /usr/share/;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
}
}
To make a long story short, I have an osCommerce installation that has been running on an Apache server for years using osCommerce's "Search Engine Friendly links" so that the links look like product_info.php/products_id/26 instead of product_info.php?products_id=26.
Well, now I've moved to an Nginx server with PHP5 and the Search Engine Friendly links just won't work for me now. BUT I have links all across the web pointing to my shop using the "friendly" links, so I have to figure out a way to redirect any url that is like this:
product_info.php/products_id/26
into this
product_info.php?products_id=26
and
index.php/cPath/19
into
index.php?cPath=19
and
product_info.php/cPath/19/products_id/207
into
product_info.php?cPath=19&products_id=207
Anyone good with Nginx rewrite rules, or who knows how to make the osCommerce built-in SEO urls work with Nginx? The osCommerce urls don't require any htaccess rewrite rules; it looks like it's all taken care of using PHP code.
nginx.conf:
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server_names_hash_bucket_size 10240;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-available/*.vhost;
}
site.com.vhost:
server {
listen *:80;
server_name site.com www.site.com;
root /var/www/clients/client23/web5/web;
index index.php index.html index.htm;
#location ~ \.shtml$ {
# ssi on;
#}
error_log /var/log/ispconfig/httpd/site.com/error.log;
access_log /var/log/ispconfig/httpd/site.com/access.log combined;
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location /stats {
index index.html index.php;
auth_basic "Members Only";
auth_basic_user_file /var/www/clients/client23/web5/web/stats/.htpasswd_stats;
}
location ^~ /awstats-icon {
alias /usr/share/awstats/icon;
}
location ~ \.php$ {
try_files /5lbe4fd76b7f89.htm #php;
}
location #php {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/lib/php5-fpm/web2.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
}
# Static Contents
location ~* ^.+.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires 1y;
}
# CSS and JS
location ~* ^.+.(css|js)$ {
access_log off;
log_not_found off;
}
server_tokens off;
error_page 400 /400.php;
error_page 401 /401.php;
error_page 403 /403.php;
error_page 404 /404.php;
error_page 405 /405.php;
error_page 500 /500.php;
error_page 502 /502.php;
error_page 503 /503.php;
recursive_error_pages off;
fastcgi_intercept_errors on;
# Inaccessible locations
location ~ ^/includes/.*\.php$ { return 404; }
location ~ ^/administrator/includes/.*\.php$ { return 404; }
location ^~ /administrator/backups { return 404; }
location ^~ /download { return 404; }
location ^~ /cgi-bin { return 404; }
location ^~ /mail { return 404; }
location ^~ /pub { return 404; }
location ^~ /sql { return 404; }
location ^~ /temp { return 404; }
location ~ /\. { deny all; access_log off; log_not_found off; }
location ~ \.(tpl|log|sql)$ {deny all; access_log off; log_not_found off; }
location / {
#if (!-e $request_filename) { rewrite ^(.*)$ /index.php; }
fastcgi_pass unix:/var/lib/php5-fpm/web2.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
rewrite ^/(.*)-(.*).html$ /index.php?cPath=$2&$query_string;
rewrite ^/(.*)-m-([0-9]+).html$ /index.php?manufacturers_id=$2&$query_string;
rewrite ^/(.*)-pi-([0-9]+).html$ /popup_image.php?pID=$2&$query_string;
rewrite ^/(.*)-t-([0-9]+).html$ /articles.php?tPath=$2&$query_string;
rewrite ^/(.*)-a-([0-9]+).html$ /article_info.php?articles_id=$2&$query_string;
rewrite ^/(.*)-pr-([0-9]+).html$ /product_reviews.php?products_id=$2&$query_string;
rewrite ^/(.*)-pri-([0-9]+).html$ /product_reviews_info.php?products_id=$2&$query_string;
rewrite ^/(.*)-i-([0-9]+).html$ /information.php?info_id=$2&$query_string;
}
location /administrator/ {
auth_basic "Members Only";
auth_basic_user_file /var/www/clients/client23/web5/web/administrator/.htpasswd;
location ~ \.php$ {
try_files /wj70wjksdkj2jiejlsjdslj.htm #php;
}
}
}
Here we go:
rewrite "^/product_info.php/products_id/(\d+)" /product_info.php?products_id=$1 permanent;
rewrite "^/index.php/cPath/(\d+)" /index.php?cPath=$1 permanent;
rewrite "^/product_info.php/cPath/(\d+)/products_id/(\d+)" /product_info.php?cPath=$1&products_id=$2 permanent;
I've got Freebsd 8 srv with nginx, php, mysql, phpBB forum, local extjs app, bugzilla, joomla and PhpMyAdmin (/pma)
The problem is when I go to pma and login through I'm redirected to domain_name/index.php?token... instead of /domain_name/pma/index.php?token...
Same thing happes when I login to joomla admin part (domain_name/administraton/index.php. redirected to domain_name/index.php)
I understand that is a location config issue probably, but i cant find out where it is.
Config below:
user www;.
worker_processes 4;
pid /var/run/nginx.pid;
error_log /var/log/nginx-error.log warn;
events {
worker_connections 1024;
use kqueue;
}
http {
gzip on;
gzip_static on;
gzip_vary on;
gzip_http_version 1.1;
gzip_min_length 700;
gzip_comp_level 6;
gzip_disable "msie6";
include mime.types;
default_type application/octet-stream;
# log options.
log_format main '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" '
'"$gzip_ratio"';
# nginx options
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server_tokens off;
# fastcgi
fastcgi_intercept_errors on;
# virtual server
server {
listen 80;
server_name domain_name www.domain_name;
server_name_in_redirect off;
rewrite 301 http://domain_name$request_uri;
access_log /var/log/haim_access_log main;
error_log /var/log/haim_error_log error;
root /usr/local/www;
# phpBB: Support Clean (aka Search Engine Friendly) URLs
location / {
try_files $uri $uri/ /index.php?$args;
}
# Joomla: caching of files
location ~* \.(ico|pdf|flv)$ {
expires 30d;
}
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ {
expires 14d;
}
# Joomla: deny running scripts inside writable directories
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ {
return 403;
error_page 403 /403_error.html;
}
# error pages 40x
error_page 404 /40x.html;
location = /nginx-distr/40x.html {
}
# phpBB 3 forum config
location /forum {
}
# phpBB 3: Deny access to internal phpbb files.
location ~ /(config\.php|common\.php|includes|cache|files|store|images/avatars/upload) {
root /usr/local/www/forum;
deny all;
# deny was ignored before 0.8.40 for connections over IPv6.
# Use internal directive to prohibit access on older versions.
# internal;
}
# phpMyAdmin
location ~ /pma4/(.*\.php)$ {
root /usr/local/www/pma4;
index index.php;
fastcgi_pass localhost:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/www/pma4/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www/pma4;
}
# bugzilla
location ~ ^/bugzilla/(.*\.cgi) {
fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock;
fastcgi_param SCRIPT_FILENAME /usr/local/www/bugzilla/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www/bugzilla;
include fastcgi_params;
}
# php
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}
# cgi
location ~ [^/]\.cgi(/|$) {
fastcgi_pass unix:/var/run/fcgiwrap/fcgiwrap.sock;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
}
# phpBB: Deny access to version control system directories.
location ~ /\.svn|/\.git {
deny all;
}
# Original: block access for .htpasswd
location ~ /\.ht {
deny all;
}
}
}
This configuration should help
location /pma4 {
root /usr/local/www;
index index.php;
location ~ .*\.php$ {
fastcgi_pass localhost:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/www/pma4/$1;
fastcgi_param DOCUMENT_ROOT /usr/local/www;
}
}
After days smashing my head on the keyboard I finally found the real solution for this problem and I'm sharing here as this thread still have high priority on google search.
As stated on the link : http://www.samundra.com.np/use-phpmyadmin-with-nginx-and-php7/1374
To solve the problem, you should add the following block of code to your nginx default site-available, you will access it with :
sudo nano /etc/nginx/sites-available/default
The block:
# Phpmyadmin Configurations
location /phpmyadmin {
root /usr/share/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
try_files $uri =404;
root /usr/share/;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_param HTTPS on; # <-- add this line
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
root /usr/share/;
}
}
# Dealing with the uppercased letters
location /phpMyAdmin {
rewrite ^/* /phpmyadmin last;
}
I hope this helps someone one day...