I have two applications: HTML+JS frontend and PHP backend. I would like to set Nginx up so that both are served from the same domain. Requests to the backend are made uing URLs starting with /api.  My attempt was this:  server {     root /path/to/frontend;     index index.html;     server_name example.com;      location / {         try_files $uri $uri/ /index.html;     }      location /api {         alias /path/to/backend;         index index.php;         try_files $uri $uri/ /index.php;     }      location ~ \.php$ {         fastcgi_pass 127.0.0.1:9000;         fastcgi_index index.php;         include fastcgi_params;     } }   However, for all requests to the backend, I end up with a 404: primary script unknown.  Is there a way to achieve what I'm trying to do here? How?
107373
Due to a  in nginx I was  to switch my alias directive with a root directive. Unfortunately this now breaks my static files, which are located in a different directory to my site path (mysite.com/blog -> /var/www/mysite/wordpress). How can I get around this, without changing my static file structure? Here's my full location block:  location /blog {     root /var/www/mysite/wordpress;     try_files $uri $uri/ /blog/index.php$is_args$args;      location ~ \.php {         fastcgi_pass 127.0.0.1:9000;         include fastcgi_params;         fastcgi_split_path_info ^(?:\/blog\/)(.+\.php)(.*);         fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;     } }
96307
My IP xxx.xxx.xxx.xx is pointing to example.com at GoDaddy but I just noticed that when I type the IP in browser, it doesn't redirect to the website, how can do this? I am sure this will happen through httpd.conf but unsure about what I need to add.
95144
Is it possible to configure Apache to have different virtual hosts listening on the same IP address, same port, such that certain paths (not the full domain, just the local path) will direct to one virtual host, and others will default to the other?  For example:  #All requests to www.mysite.com/special-url go here  &lt;VirtualHost /special-url:80&gt;   DefaultType application/x-httpd-php   ServerName server1   Document Root "/home/me/server1"   &lt;Directory "/home/me/server1"&gt;     AllowOverride None     Order allow, deny     allow from all   &lt;/Directory&gt; &lt;/VirtualHost&gt;  #All other requests go here  &lt;VirtualHost *:80&gt;   DefaultType application/x-httpd-php   ServerName server1   Document Root "/home/me/server2"   &lt;Directory "/home/me/server2"&gt;     AllowOverride None     Order allow, deny     allow from all   &lt;/Directory&gt; &lt;/VirtualHost&gt;   This server configuration doesn't work, and neither does adding wildcard combinations to the first VirtualHost tag (e.g. VirtualHost */special-url:80). Instead, when I run this, Apache directs requests to /special-url to /home/me/server1. But if I look for /foo it will still look for that in server1 and return 404 even if there is a directory called foo in /home/me/server2.  Is there any way to have one VirtualHost just for certain URLs, and another VirtualHost for all other URLs?
88295
I am trying to make my url from this:  example.com/view.php?id=15   To this:  example.com/watch/15   My code in .htaccess is as follows:  Options -Indexes Options +FollowSymlinks RewriteEngine On RewriteRule ^watch/([^/]+) view.php?id=$1 [NC]   Now if I go to example.com/watch/15 it loads the content but without any JS, CSS because in this case it looks for CSS and JS under the /watch folder which doesn't exist.  How do I make this option work properly? I don't want to create watch folder and copy-paste CSS and JS so it will embed properly.
105322
I have few different vhost created and every one has its own folder in /var/www/ like this /var/www/example1/ /var/www/example2/  Now, when I type url with www www.example1.com it points to the /var/www/example1/index.html so that's working fine, but when I type without www example1.com it points to /var/www/ and I can see all the folders, I don't have index.html in /var/www/. I looked  and created .htaccess in /var/www/:     RewriteEngine On     RewriteBase /     RewriteCond % ^example1.com [NC]     RewriteRule ^(.*)$ http://www.example1.com/$1 [L,R=301]  but it's not working. This is how the all vhosts look like: &lt;VirtualHost *:80&gt;         ServerAdmin webmaster@localhost         ServerName *example1*         ServerAlias *.*example1*         DocumentRoot /var/www/example1         &lt;Directory /&gt;                 Options FollowSymLinks                 AllowOverride All         &lt;/Directory&gt;         &lt;Directory /var/www/example1/&gt;                 Options Indexes FollowSymLinks MultiViews                 AllowOverride All                 Order allow,deny                 allow from all         &lt;/Directory&gt;          ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/         &lt;Directory &quot;/usr/lib/cgi-bin&quot;&gt;                 AllowOverride None  I have cleared browser cache. Any idea how to fix this?
31509
I have a rather large and slow (complex data, complex frontend) web application build in RoR and served by Puma with nginx as reverse proxy. Looking at the nginx error log, I see quite a few entries like:  2014/04/08 09:46:08 [warn] 20058#0: *819237 an upstream response is buffered to a temporary file      /var/lib/nginx/proxy/8/47/0000038478 while reading upstream,      client: 5.144.169.242, server: engagement-console.foo.it,      request: "GET /elements/pending?customer_id=2&amp;page=2 HTTP/1.0",      upstream: "http://unix:///home/deployer/apps/conversationflow/shared/sockets/puma.sock:/elements/pending?customer_id=2&amp;page=2",      host: "ec.reputationmonitor.it",      referrer: "http://ec.foo.it/elements/pending?customer_id=2&amp;page=3"   I am rather curious as it's very unlikely that the page remains the same for different users and different user interactions, and I would not think that buffering the response on disk is necessary/useful.  I know about proxy_max_temp_file_size and setting it to 0, but it seems to me a little bit awkward (my proxy tries to buffer but has no file where to buffer to... how can that be faster?).  My questions are:   How can I remove the [warn] and avoid buffering responses? Is it better to turn off proxy_buffering or to set proxy_max_temp_file_size to 0? Why? If nginx buffers a response: When does it serve the buffered response, to whom, and why? Why nginx turns proxy_buffering on by default and then [warn]s you if it actually buffers a response? When does a response trigger that option? When it takes > some seconds (how many?) to serve the response? Is this configurable?   TIA, ngw.
43638
My company has two websites a main one at www.example.com and one at subdomain.example.com which is a subdomain of the first and is our self hosted blog.   The way Google sees these with the www or no-www (called naked for now on) is that each of these actually are different when the www or naked version is used/not used in the front of the domain. I completely understand this. It is also advised that both should be set up in the Google Webmaster Tools, which I have done. Correct me if I am wrong on that in regard to having both set up.  Now the way it appears is that we can set a preferred domain up in Webmaster Tools only at the root domain level. The subdomain cannot have this and actually says the following:  **Restricted to root level domains only**.  So it appears that the domain should follow what the root domain says, which on our preferred one says to display the www.example.com and not the naked version. That is one issue I have in that one displays one way and the other displays another.   Is it that we have the wrong redirects in place for the subdomain? Another question is does this have any affect on SEO in regards to duplicate content on the web in how we have set this up?
23776
I've checked out quite a few other answers to similar questions as well as tutorials on DigitalOcean, etc., with no success. Sorry for what is probably a very obvious problem - I'm new to this.  Essentially, I need to set up redirects so that http://, ., and . all redirect to https://.  Currently, https:// works fine and http:// redirects to https://. I need to redirect www traffic because the SSL cert is only configured for non-www. However, when I've tried to add another server block to the config to redirect www (http and https) to https://, the server closes the connection on all 4 variants.  Here's my config:  # HTTP - redirect to HTTPS server {     listen 80;     server_name www.example.com example.com;     return 301 https://example.com$request_uri; }  # HTTPS www - redirect to non-www RESETS CONNECTION #server { #    listen 443; #    server_name www.example.com; #    return 301 https://example.com$request_uri; #}   # HTTPS — proxy all requests to the Node app server {     # Enable HTTP/2     listen 443 ssl http2;     server_name example.com;      # Use the Let’s Encrypt certificates     ssl_certificate /etc/not/my/path/live/example.com/fullchain.pem;     ssl_certificate_key /etc/not/my/path/live/example.com/privkey.pem;      # Include the SSL configuration from cipherli.st     include snippets/ssl-params.conf;      location / {         proxy_set_header X-Real-IP $remote_addr;         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;         proxy_set_header X-NginX-Proxy true;         proxy_pass http://0.0.0.0:2368/;         proxy_ssl_session_reuse off;         proxy_set_header Host $http_host;         proxy_cache_bypass $http_upgrade;         proxy_redirect off;     } }   Can anyone tell me what I'm doing wrong? Again I know it's probably painfully obvious but I just can't get this to work. Should I be doing this with something other than an NGINX redirect?
124288
I need a single Wordpress installation to be available from both the main domain (www.example.com) via HTTP and a subdomain (secure.example.com) via HTTPS.  Of course i can just map the subdomain to the Wordpress folder in Nginx config. But will Wordpress be aware that it is called via HTTPS and change all links on the pages to HTTPS ?  Also, how i can i force certain pages to be automatically redirected to their HTTPS equivalent permalink (and then back again to HTTP) ?
6152
When I set up a site in multiple languages, how should I set up my URLs for search engines and usability?  Let's say my site is www.example.com, and I'm translating into French and Spanish. What is best for usability and SEO?  Directory option:  http://www.example.com/sample.html http://www.example.com/fr/sample.html http://www.example.com/es/sample.html   Subdomain option:  http://www.example.com/sample.html http://fr.example.com/sample.html http://es.example.com/sample.html   Filename option:  http://www.example.com/sample.html http://www.example.com/sample.fr.html http://www.example.com/sample.es.html   Accept-Language header:  Or should I simply parse the  header and generate content server-side to suit that header?  Is there another way to do this? If the different language versions don't have different urls, what do I do about the search engines?    UPDATE 2011-12-06  Google has new recommendations for meta tags for explicitly pointing to other language content: .  UPDATE 2012-05-25  Related but not precisely:   UPDATE 2013-06-12  includes discussion of several URL schemes directly relevant to the question.
117347
I am working on an apache2 reverse proxy vhost. When the server behind apache is down, the first request to apache shows the error page of course.   But at subsequent requests it seems apache delays for some time before asking the backend server again. During all this time (which is short but in development I don't want a delay at all) only the apache error page is shown to the browser, although the backend server is already up.  Where is this setting in apache, what is this behaviour, and how can I set the delay time to zero?  Edit: I am not trying to change the timeout for a single request. I want to change the blocking time. It is my experience that apache blocks further requests for a certain time before asking a backend server again that has failed once.   Edit2: This is what apache delivers:  Service Temporarily Unavailable  The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.  Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.7 with Suhosin-Patch proxy_html/3.0.0 Server at localhost Port 80  After hitting Ctrl-R in firefox for 60 seconds the page finally appears.
9132
I have a problem with my page. I'm trying to make a "Contact Us" page. It's working perfectly fine design-wise. But when I try to send the form to the same page as origin. It returns 404 error.  It only happens when I'm sending the form. I've tried both with GET and POST requests. Nothing seems to work.  I've even commented out the PHPMailer part. It's caused entirely by the extra variables.  If it helps anything, they're "name", "email" and "message".
108467
I am exploring the use of HAProxy as a balancer in front of a set of web apis that run on IIS.   node1.myapp.mycompany.com node2.myapp.mycomapny.com   We are currently using Host Headers to correctly resolve the right web application on IIS.  For example, we may have otherapp.mycompany.com running on the same server/port, but using Host Headers IIS knows which one to serve up.  My initial attempt at HAProxy left me with 404 errors, because I was not including the host headers in my request, and so IIS was serving back the default site bound to the given IP, and not resolving by host name.    The fix left me with something like this:  frontend localnodes     bind *:80     mode http     default_backend nodes  backend nodes     mode http     balance roundrobin     option forwardfor     reqirep ^Host: Host:\ node1.myapp.mycompany.com     server web01 node1.myapp.mycompany.com:80   This works great for a single backend, but I am left scracthing my head on how to include the correct host headers depending on which backend is serving up the request:  backend nodes     mode http     balance roundrobin     option forwardfor     reqirep ^Host: Host:\ node1.myapp.mycompany.com     server web01 node1.myapp.mycompany.com:80     server web02 node2.myapp.mycompany.com:80   The above does not work whenever node2 is used because it doesn't resolve correctly in IIS (node2 in this case is on a different server, and therefore different IP.  In fact, if they were running on the same server/ip I suspect the request work "work", but they would all be served by node1 per the host header).     Is it possible to set the host based on the url of the backend used to serve up the request? If so, this implies my checks also need to provide the correct host header based on backend, how would that be done?   Edit: Am using HA-Proxy version 1.7.9 2017/08/18  Let me give this just a little more background.  We used to have just myapp.mycompany.com serving up api requests.  We need to expand it.  Our clients will still call myapp.mycompany.com, but that will just point to the HAProxy, which will balance it out to node1.myapp.mycompany.com and node2.myapp.mycompany.com.  Our current server configurations have us binding a single IP address on each server, so we use host headers to resolve.
83779
Ok, so I have an index.php file which has to process many different file types.  how do I guess the filetype based on the REQUEST_URI.  If I request http://site/image.jpg, and all requests redirect through index.php, which looks like this  &lt;?php    include('/www/site'.$_SERVER['REQUEST_URI']); ?&gt;   How would I make that work correctly?  Should I test based on the extension of the file requested, or is there a way to get the filetype?
78999
I have a brand new VM with CenotOS 7 Minimal Installation.  What I want to happen is to configure Nginx to serve static files from a directory on localhost:80.  My directory is /home/kenny/projects/kcrypt/dist/.  Here are the contents of my /etc/nginx/nginx.conf:  # this is set to root in order to rule out # any permission related issues. user root;      worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid;  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"';      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;      server {         listen       80 default_server;         listen       [::]:80 default_server;         root         /home/kenny/projects/kcrypt/dist/;         index index.html;          location / {         }     } }   when I run curl http://localhost I get this response:  &lt;html&gt; &lt;head&gt;&lt;title&gt;403 Forbidden&lt;/title&gt;&lt;/head&gt; &lt;body bgcolor="white"&gt; &lt;center&gt;&lt;h1&gt;403 Forbidden&lt;/h1&gt;&lt;/center&gt; &lt;hr&gt;&lt;center&gt;nginx/1.12.2&lt;/center&gt; &lt;/body&gt; &lt;/html&gt;   I have tried giving all kinds of permissions to any directories that I can think of.   In the end I configured Nginx to run as root.   I have reinstalled the OS multiple times already and can't get it to work.   P.S.   This is what I found in /var/log/nginx/error.log  2018/02/27 21:33:19 [error] 15689#0: *1 open() "/home/kenny/projects/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost" 2018/02/27 21:33:35 [error] 15690#0: *2 open() "/home/kenny/projects/kcrypt/dist/index.html" failed (13: Permission denied), client: 127.0.0.1, server: , request: "GET / HTTP/1.1", host: "127.0.0.1" 2018/02/27 21:33:38 [error] 15690#0: *3 open() "/home/kenny/projects/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost"   I don't get what it wants... I have given it all the permissions that I can.   This is what I have in the root directory:  [root@vm3 dist]# ll total 368K drwxrwxrwx. 2 root root   98 Feb 26 23:16 . drwxrwxrwx. 6 root root  234 Feb 27 21:26 .. -rwxrwxrwx. 1 root root 1.2K Feb 26 23:16 favicon.ico -rwxrwxrwx. 1 root root 1.7K Feb 26 23:16 index.html -rwxrwxrwx. 1 root root 175K Feb 26 22:53 index.js -rwxrwxrwx. 1 root root  297 Feb 26 23:16 manifest.json -rwxrwxrwx. 1 root root 179K Feb 26 22:53 styles.css   P.S. 2  I have tried putting my static files in /var/www/kcrypt/dist/, but with no result.  I still get the same error messages:   2018/02/27 23:18:11 [error] 16157#0: *1 open() "/var/www/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost" 2018/02/27 23:20:58 [error] 16535#0: *1 open() "/var/www/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost" 2018/02/27 23:21:30 [error] 16564#0: *1 open() "/var/www/kcrypt/dist/index.html" failed (13: Permission denied), client: ::1, server: , request: "GET / HTTP/1.1", host: "localhost"
118241
I'm trying to set up my environment such that surveyadmin.local points at one directory and surveyadmin.local/api points at another.  However, no matter what I change, the /api URL always results in a call to the directory that surveyadmin.local is pointing at. Here's a sample error from the error log specified in the vhost config:  2013/08/09 17:20:07 [error] 8911#0: *1 open() "/srv/http/surveytool/admin/build/app.php" failed (2: No such file or directory), client: 10.0.2.2, server: surveyadmin.local, request: "GET /api/organizations HTTP/1.1", host: "surveyadmin.local"   Note that the error refers to a path of /srv/http/surveytool/admin/buid/, instead of the /srv/http/surveytool/api/SurveyTool/web/ that was expected.  Here's my config for the vhost in question:  server {     listen 80;     server_name surveyadmin.local;      location / {         root /srv/http/surveytool/admin/build;         index index.html;     }      location /api {         root /srv/http/surveytool/api/SurveyTool/web;         index app.php;         try_files $uri $uri/ /app.php?$query_String;         location ~ \.php(?|$) {             fastcgi_pass unix:/var/run/php5-fpm.sock;             fastcgi_index app.php;             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;             include /etc/nginx/fastcgi_params;         }     }     access_log  /var/log/nginx/surveyadmin.access.log;     error_log   /var/log/nginx/surveyadmin.error.log debug; }   I have tried changing the word "root" to "alias" under the location /api block. I've tried setting up a second virtual host and doing a proxy forward (with proxy_pass) to that vhost.  This seems like it shouldn't be that difficult, so I'm assuming my error is a simple one that I just haven't seen yet.  Can anyone spot any obvious problems with the above config?
49237
We are using Nginx to serve static files on a development platform. As it is a development platform, we'd like to disable caching so that each change is propagated to the server. The configuration of the VHost is quite simple:  server {   server_name  static.server.local;   root /var/www/static;    ## Default location   location / {     access_log        off;     expires           0;     add_header        Cache-Control private;   }  }   When we access an HTML file (http://static.server.local/test.html), we have no issue: the server returns a code 304 Not Modified as long as the file is not changed, and a 200 OK response with the modified file when the file is changed. However, it seems to behave differently with a Javascript or a CSS file. Once the file is changed, we get a 200 OK response as expected, but with the old text. Is there an internal cache mechanism in Nginx that could explain this behaviour? Or some configuration that we should add?    As a side note, here is the header returned by Nginx when the file has been modified (it seems correct):  Accept-Ranges:bytes Cache-Control:max-age=0 private Connection:keep-alive Content-Length:309 Content-Type:text/css Date:Fri, 13 May 2011 14:13:13 GMT Expires:Fri, 13 May 2011 14:13:13 GMT Last-Modified:Fri, 13 May 2011 14:13:05 GMT Server:nginx/0.8.54   Edit After trying different settings with the expires directive and Cache-Controlheader, I made some further investigations. In fact, the server is installed on a VirtualBox guest Ubuntu, and data are read from a shared folder that is on the Mac OSX host. If the file is edited from an IDE (NetBeans) on the host, it seems that changes do not appear whereas if I edit it directly on the guest (using VIM), it is refreshed. The strange thing is it does not behave similarly with HTML files. Quite puzzling.  Edit 2 (ANSWER) Indeed, the origin of the issue was more on the VirtualBox side. Or rather a conflict between VirtualBox and the "sendfile" option of the server. This link  gave me the solution: switch the sendfile flag in the server configuration to off:  sendfile  off;   Hope this could also help other person using VirtualBox for development. :) There are some additional information on the .