I think I'll cross post to stackoverflow as well; Here's my issue:
I have installed an ssl certificate on my server, and read a whole lot and did all the different suggested things, but I cannot seem to get the $_SERVER['HTTPS'] variable to show up. Someone please help. Here's my config:
Server:
Linode
Ubuntu 8.02LTS
nginx - latest
created a vhost:
server {
listen 443;
server_name www.buzzonstage.com;
rewrite ^/(.*) https://buzzonstage.com/$1 permanent;
}
server {
listen 443;
server_name buzzonstage.com;
ssl on;
ssl_certificate /usr/local/nginx/conf/buzzonstage.com.pem;
ssl_certificate_key /usr/local/nginx/conf/buzzonstage.com.key;
access_log /home/maksimize/public_html/buzzonstage.com/log/access.log;
error_log /home/maksimize/public_html/buzzonstage.com/log/error.log;
location / {
root /home/maksimize/public_html/buzzonstage.com/public/;
index index.php index.html;
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/maksimize/public_html/buzzonstage.com/public/$fastcgi_script_name;
fastcgi_param HTTPS on;
}
}
server {
listen 80;
server_name www.buzzonstage.com;
rewrite ^/(.*) http://buzzonstage.com/$1 permanent;
}
server {
listen 80;
server_name buzzonstage.com;
access_log /home/maksimize/public_html/buzzonstage.com/log/access.log;
error_log /home/maksimize/public_html/buzzonstage.com/log/error.log;
location / {
root /home/maksimize/public_html/buzzonstage.com/public/;
index index.php index.html;
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include /usr/local/nginx/conf/fastcgi_params;
fastcgi_param SCRIPT_FILENAME /home/maksimize/public_html/buzzonstage.com/public/$fastcgi_script_name;
The verification from digicert comes back accurate, but I get a message saying that some info may not be secure - I understand this is the case because of the various links to non-secure pages on the site. The phpinfo shows up green https;
But in order for a certain drupal module to work - securepages - I need to be able to show a that variable in the $_SERVER array. Can someone please help?
Thanks!
That Twitter module is breaking SSL. Modify it so it will pass only through SSL (requires rewriting the widget so it loads locally, yes it's possible), and everything should work.
The phpinfo shows up green https;
This is good. Because phpinfo works with $_SERVER['HTTPS'] variable. And it's certainly defined.
but I get a message saying that some info may not be secure
But in order for a certain drupal module to work - securepages
I need to be able to show a that variable in the $_SERVER array.
Hmm, may be this modules trying to work without https? For example through AJAX?
And where they getting answer, HTTPS is not defined.
Try to check this, by adding fastcgi_param HTTPS on; to NON https section of your config. I think all will start working. But obvious, it's a cheat...
Related
I have a Nginx webserver (I'm very new at Nginx). This is my Nginx config file:
server {
listen 80;
listen [::]:80;
server_name example.com *.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl on;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_session_timeout 5m;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name example.com *.example.com;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
I have a DNS-record set to allow wildcard subdomains. My question now is: how can I "catch" the current subdomain in PHP?
For example: if the subdomain is http://demo.example.com, I want to go to
http://example.com?subdomain=demo.
Thanks in advance!
The host header will already contain the client requested domain. You could just grab that in php
$domain = $_SERVER['HTTP_HOST'];
However, unless you have a wildcard SSL certificate then you are going to have a bad time.
SSL negotiation takes place before any HTTP exchange so if the subdomain and the SSL cert don't agree the connection will fail.
Also, changing the subdomain to a query string is a bad idea:
You'll lose the ability to configure each subdomain separately within
Nginx and force lots of redirects and rewrites for every client
connection.
Your SEO will suck.
What will your page links look like?
If I have one.example.com and you have two.example.com the requests will become:
example.com?subdomain=one
example.com?subdomain=two
Both of those requests are now being handled by the same index page on example.com. Is that really what you want?
Add the following server to your Nginx. don't forget to restart Nginx service
server {
server_name demo.example.com;
rewrite ^(.*) http://example.com?subdomain=demo;
}
Update
according to the comment, for dynamic redirection, you should get the subdomain name by regex
server {
listen 80;
server_name ~^(?<name>.+)\.example\.com$;
return 301 http://example.com/?subdomain=$name;
}
Also, you can rewrite it instead of 301 redirects by
rewrite ^(.*) http://example.com/?subdomain=$name;
See this document for more info.
I have some troubles with nginx.
I created new project on Symfony3. Config.php says, that everything is good. dev_app.php - too.
But when I try to open site without any other route, like sitename.com nginx returns 403 error.
When I try to start symfnoy server (bin/console server:start) It's forbidden too.
sitename.com:8000 returns me fail to opening this page.
site-available config is
upstream phpfcgi {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name localhost;
root /home/staging/www/web;
error_log /home/staging/logs/staging.error.log;
access_log /home/staging/logs/staging.access.log;
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|config)\.php(/|$) {
fastcgi_pass phpfcgi;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
I added new entity with crud, but any actions doesn't work.
I will be glad for any help. Thanks
Try to add
rewrite ^/app\.php/?(.*)$ /$1 permanent;
in the server section before any location sections (after the root /home/staging/www/web; line, for example).
Situation:
I deployed my php project as a web server in the machine A, using nginx and fastcgi, and the config file is as following:
server {
listen 80;
server_name alpha.kimi.com;
index index.html index.htm index.php;
root /alidata/www/;
location ~ .*\.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location / {
root /www/admin/;
index index.php;
if (!-f $request_filename){
rewrite ^/(.+)$ /index.php?$1& last;
}
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
access_log /data/log/nginx/access/output.log;
error_log /data/log/nginx/access/error.log;
}
so when I make a 'GET' request from my local machine as:
curl http://alpha.kimi.com/app/redirect/taskpush?build=10&gcdata=1
there will be json returned
{"res":200,"msg":"success","extra":[]}
However when I made the same request in the machine A, it just hanged there, and returned nothing. I also tried:
curl http://localhost/app/redirect/taskpush?build=10&gcdata=1
and
curl http://localhost:9000/app/redirect/taskpush?build=10&gcdata=1
all not working. I don't know what is the problem.
You need to configure nginx to listen via localhost or 127.0.0.1 for it to work.
See http://nginx.org/en/docs/http/ngx_http_core_module.html#listen for full instructions.
You can add multiple listen statements eg:
listen localhost;
listen 127.0.0.1;
Also see this for more detail: https://serverfault.com/questions/655067/is-it-possible-to-make-nginx-listen-to-different-ports
Hi every one I am new to magento. I've been trying to install magento 1.9.0.0 on with nginx server on Ubuntu 14.04LTS but I can't get started. I can see default page see below
magento default page
but whenever I try to log in it, server fails with UNABLE TO CONNECT error.
here is my virtual host
server {
listen 80;
listen [::]:80;
server_name www.mymagento.com;
root /var/www/magento;
index index.php;
#need it to execute php
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
include fastcgi.conf;
}
}
I already tried other solution like updating core_config_data web/unsecure/base_url and web/secure/base_url they contain my base url.
I tried reloading cache. there is nothing in nginx log neiher.
Thank you for helping me :-)
You have nothing to redirect URIs to the Magento common front handler. As a minimum you should add:
location / {
try_files $uri $uri/ /index.php;
}
But I suggest that you check this site for more.
Hi as Richard SMITH said, my virtual host was missing some lines to somehow redirect to front handler. As I have just begin to use Nginx, I won't be able to explain each lines but after strugling with Nginx this config works for me (I also needed to add self signed certificate to config to make it work).
server {
listen 80;
listen [::]:80;
listen 443 default ssl;
server_name www.mymagento.com;
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
root /var/www/magento;
index index.php;
location / {
index index.html index.php;
autoindex on;
#If missing pass the URI to Magento's front handler
try_files $uri $uri/ #handler;
expires max;
}
#need it to execute php
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
include fastcgi_params;
include fastcgi.conf;
}
## Magento uses a common front handler
location #handler {
rewrite / /index.php;
}
}
I'm fairly new to nginx and assumed it would be very straightforward to serve php with it since that setup is so common, but it seems like it's much more complex than I anticipated.
Here's my config..
server {
listen 80;
server_name domain.com www.domain.com;
location / {
root /srv/www/domain.com/public_html;
index index.php;
}
# serve static files directly
#location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$
# access_log off;
# expires 30d;
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_pass /var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
If I replace the "index.php" with a "index.html" file, nginx serves up the html perfectly.
I've seen guides that recommend modifying anything from iptables to php-fpm to the php.ini, to fast-cgi to sites-available..?
I'm not sure what many of these tutorials are trying to do exactly... for now I'd just like my index.php to serve up phpinfo(). What's the next step to troubleshoot the 404 error?
Is there a clear guide that goes over the various options available for serving php with nginx?
Debian Wheezy 7.3 on xen
Try this config:
server {
listen 80;
server_name domain.com www.domain.com;
root /srv/www/domain.com/public_html;
index index.php;
location ~ ^(.+\.php)(/.*)?$ {
fastcgi_pass localhost:9000;
include fastcgi_params;
}
}
(assuming your index.php file is in /srv/www/domain.com/public_html)