How to force non-www -> www routing for subfolders in Nginx?Help needed setting up nginx to serve static filesHow do I get PHP 5.3.3 working with Nginx on CentOS 5.5?How to force or redirect to SSL in nginx?nginx load balancer rewrite to listen portNginx/Apache: set HSTS only if X-Forwarded-Proto is httpsOCSP validation - unable to get local issuer certificatenginx seems to be ignoring ssl_ciphers settingIntermittent nginx timeouts having jetty as upstream serverSSL_read() failed (SSL: error:140943F2:SSL routines:SSL3_READ_BYTES:sslv3 error in nginxNGINX virtual host config for Magento2 in a subfolder

How does one intimidate enemies without having the capacity for violence?

What are the differences between the usage of 'it' and 'they'?

Show that if two triangles built on parallel lines, with equal bases have the same perimeter only if they are congruent.

What does it mean to describe someone as a butt steak?

What is the word for reserving something for yourself before others do?

What does "Puller Prush Person" mean?

How old can references or sources in a thesis be?

Are the number of citations and number of published articles the most important criteria for a tenure promotion?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Do VLANs within a subnet need to have their own subnet for router on a stick?

Problem of parity - Can we draw a closed path made up of 20 line segments...

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

How does strength of boric acid solution increase in presence of salicylic acid?

Have astronauts in space suits ever taken selfies? If so, how?

"to be prejudice towards/against someone" vs "to be prejudiced against/towards someone"

How could an uplifted falcon's brain work?

What typically incentivizes a professor to change jobs to a lower ranking university?

How can I make my BBEG immortal short of making them a Lich or Vampire?

Test if tikzmark exists on same page

Which models of the Boeing 737 are still in production?

What's the point of deactivating Num Lock on login screens?

What's the output of a record cartridge playing an out-of-speed record

Why can't I see bouncing of a switch on an oscilloscope?

Is a tag line useful on a cover?



How to force non-www -> www routing for subfolders in Nginx?


Help needed setting up nginx to serve static filesHow do I get PHP 5.3.3 working with Nginx on CentOS 5.5?How to force or redirect to SSL in nginx?nginx load balancer rewrite to listen portNginx/Apache: set HSTS only if X-Forwarded-Proto is httpsOCSP validation - unable to get local issuer certificatenginx seems to be ignoring ssl_ciphers settingIntermittent nginx timeouts having jetty as upstream serverSSL_read() failed (SSL: error:140943F2:SSL routines:SSL3_READ_BYTES:sslv3 error in nginxNGINX virtual host config for Magento2 in a subfolder






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















My site is SSL-enabled and is called schandillia.com. And my objective is to force all access through https://www.schandillia.com...both for the homepage, as well as other pages. Following is what my Nginx conf looks like:



server 
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;


server
listen 443 default_server ssl http2; # spdy is a more performant alternative to http2
listen [::]:443 ssl http2; # spdy is a more performant alternative to http2
server_name .schandillia.com;

location /
proxy_pass http://127.0.0.1:3000;
charset UTF-8;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;




This configuration allows the following:



http://schandillia.com -> https://www.schandillia.com
schandillia.com -> https://www.schandillia.com
www.schandillia.com -> https://www.schandillia.com



However, it does not enforce www on sub-routes, e.g., schandillia.com/about, etc. What needs changing in my configuration directives?



Update: Here's the entire .conf snippet for reference:



# read more here http://tautt.com/best-nginx-configuration-for-security/

# don't send the nginx version number in error pages and Server header
server_tokens off;

include /etc/nginx/sites-available/snippets/ssl-config.conf; # importing ssl configurations

# redirect all http traffic to https
server
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
# return 301 https://$host$request_uri;
return 301 https://www.schandillia.com$request_uri;


server jpe?g

# for subdomain dev
server
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name dev.schandillia.com;

# Route for /
location /
proxy_pass http://127.0.0.1:9001;
include /etc/nginx/sites-available/snippets/proxy.conf; # importing proxy configurations




Hope this helps.










share|improve this question









New contributor




TheLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Where are your redirects? Did you omit something else here?

    – Michael Hampton
    Apr 3 at 16:00












  • Just added my location block.

    – TheLearner
    Apr 3 at 16:25











  • return 301 https://www.schandillia.com$request_uri;

    – Gerald Schneider
    Apr 3 at 16:30











  • Didn't work. https://schandillia.com/about still goes to https://schandillia.com/about and not https://www.schandillia.com/about.

    – TheLearner
    Apr 3 at 16:41


















2















My site is SSL-enabled and is called schandillia.com. And my objective is to force all access through https://www.schandillia.com...both for the homepage, as well as other pages. Following is what my Nginx conf looks like:



server 
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;


server
listen 443 default_server ssl http2; # spdy is a more performant alternative to http2
listen [::]:443 ssl http2; # spdy is a more performant alternative to http2
server_name .schandillia.com;

location /
proxy_pass http://127.0.0.1:3000;
charset UTF-8;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;




This configuration allows the following:



http://schandillia.com -> https://www.schandillia.com
schandillia.com -> https://www.schandillia.com
www.schandillia.com -> https://www.schandillia.com



However, it does not enforce www on sub-routes, e.g., schandillia.com/about, etc. What needs changing in my configuration directives?



Update: Here's the entire .conf snippet for reference:



# read more here http://tautt.com/best-nginx-configuration-for-security/

# don't send the nginx version number in error pages and Server header
server_tokens off;

include /etc/nginx/sites-available/snippets/ssl-config.conf; # importing ssl configurations

# redirect all http traffic to https
server
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
# return 301 https://$host$request_uri;
return 301 https://www.schandillia.com$request_uri;


server jpe?g

# for subdomain dev
server
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name dev.schandillia.com;

# Route for /
location /
proxy_pass http://127.0.0.1:9001;
include /etc/nginx/sites-available/snippets/proxy.conf; # importing proxy configurations




Hope this helps.










share|improve this question









New contributor




TheLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Where are your redirects? Did you omit something else here?

    – Michael Hampton
    Apr 3 at 16:00












  • Just added my location block.

    – TheLearner
    Apr 3 at 16:25











  • return 301 https://www.schandillia.com$request_uri;

    – Gerald Schneider
    Apr 3 at 16:30











  • Didn't work. https://schandillia.com/about still goes to https://schandillia.com/about and not https://www.schandillia.com/about.

    – TheLearner
    Apr 3 at 16:41














2












2








2








My site is SSL-enabled and is called schandillia.com. And my objective is to force all access through https://www.schandillia.com...both for the homepage, as well as other pages. Following is what my Nginx conf looks like:



server 
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;


server
listen 443 default_server ssl http2; # spdy is a more performant alternative to http2
listen [::]:443 ssl http2; # spdy is a more performant alternative to http2
server_name .schandillia.com;

location /
proxy_pass http://127.0.0.1:3000;
charset UTF-8;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;




This configuration allows the following:



http://schandillia.com -> https://www.schandillia.com
schandillia.com -> https://www.schandillia.com
www.schandillia.com -> https://www.schandillia.com



However, it does not enforce www on sub-routes, e.g., schandillia.com/about, etc. What needs changing in my configuration directives?



Update: Here's the entire .conf snippet for reference:



# read more here http://tautt.com/best-nginx-configuration-for-security/

# don't send the nginx version number in error pages and Server header
server_tokens off;

include /etc/nginx/sites-available/snippets/ssl-config.conf; # importing ssl configurations

# redirect all http traffic to https
server
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
# return 301 https://$host$request_uri;
return 301 https://www.schandillia.com$request_uri;


server jpe?g

# for subdomain dev
server
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name dev.schandillia.com;

# Route for /
location /
proxy_pass http://127.0.0.1:9001;
include /etc/nginx/sites-available/snippets/proxy.conf; # importing proxy configurations




Hope this helps.










share|improve this question









New contributor




TheLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












My site is SSL-enabled and is called schandillia.com. And my objective is to force all access through https://www.schandillia.com...both for the homepage, as well as other pages. Following is what my Nginx conf looks like:



server 
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
return 301 https://$host$request_uri;


server
listen 443 default_server ssl http2; # spdy is a more performant alternative to http2
listen [::]:443 ssl http2; # spdy is a more performant alternative to http2
server_name .schandillia.com;

location /
proxy_pass http://127.0.0.1:3000;
charset UTF-8;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;




This configuration allows the following:



http://schandillia.com -> https://www.schandillia.com
schandillia.com -> https://www.schandillia.com
www.schandillia.com -> https://www.schandillia.com



However, it does not enforce www on sub-routes, e.g., schandillia.com/about, etc. What needs changing in my configuration directives?



Update: Here's the entire .conf snippet for reference:



# read more here http://tautt.com/best-nginx-configuration-for-security/

# don't send the nginx version number in error pages and Server header
server_tokens off;

include /etc/nginx/sites-available/snippets/ssl-config.conf; # importing ssl configurations

# redirect all http traffic to https
server
listen 80 default_server;
listen [::]:80 default_server;
# Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
# return 301 https://$host$request_uri;
return 301 https://www.schandillia.com$request_uri;


server jpe?g

# for subdomain dev
server
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name dev.schandillia.com;

# Route for /
location /
proxy_pass http://127.0.0.1:9001;
include /etc/nginx/sites-available/snippets/proxy.conf; # importing proxy configurations




Hope this helps.







nginx reverse-proxy proxypass






share|improve this question









New contributor




TheLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




TheLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Apr 3 at 16:39







TheLearner













New contributor




TheLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Apr 3 at 15:55









TheLearnerTheLearner

1275




1275




New contributor




TheLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





TheLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






TheLearner is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Where are your redirects? Did you omit something else here?

    – Michael Hampton
    Apr 3 at 16:00












  • Just added my location block.

    – TheLearner
    Apr 3 at 16:25











  • return 301 https://www.schandillia.com$request_uri;

    – Gerald Schneider
    Apr 3 at 16:30











  • Didn't work. https://schandillia.com/about still goes to https://schandillia.com/about and not https://www.schandillia.com/about.

    – TheLearner
    Apr 3 at 16:41


















  • Where are your redirects? Did you omit something else here?

    – Michael Hampton
    Apr 3 at 16:00












  • Just added my location block.

    – TheLearner
    Apr 3 at 16:25











  • return 301 https://www.schandillia.com$request_uri;

    – Gerald Schneider
    Apr 3 at 16:30











  • Didn't work. https://schandillia.com/about still goes to https://schandillia.com/about and not https://www.schandillia.com/about.

    – TheLearner
    Apr 3 at 16:41

















Where are your redirects? Did you omit something else here?

– Michael Hampton
Apr 3 at 16:00






Where are your redirects? Did you omit something else here?

– Michael Hampton
Apr 3 at 16:00














Just added my location block.

– TheLearner
Apr 3 at 16:25





Just added my location block.

– TheLearner
Apr 3 at 16:25













return 301 https://www.schandillia.com$request_uri;

– Gerald Schneider
Apr 3 at 16:30





return 301 https://www.schandillia.com$request_uri;

– Gerald Schneider
Apr 3 at 16:30













Didn't work. https://schandillia.com/about still goes to https://schandillia.com/about and not https://www.schandillia.com/about.

– TheLearner
Apr 3 at 16:41






Didn't work. https://schandillia.com/about still goes to https://schandillia.com/about and not https://www.schandillia.com/about.

– TheLearner
Apr 3 at 16:41











1 Answer
1






active

oldest

votes


















2














Currently you only redirect from http to https. You do not have a redirect from https to https.



You could separate the listen 443 ssl default_server and the server_name www.example.com into two separate blocks. You can use the same server block for your listen 80 default_server block.



For example:



server 
listen 80 default_server;
listen [::]:80 default_server;
listen 443 default_server ssl;
listen [::]:443 default_server ssl;

return 301 https://www.schandillia.com$request_uri;


server
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.example.com;

...



Any request that is not to https://www.example.com and is not handled by another server block will be redirected to https://www.example.com.






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "2"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    TheLearner is a new contributor. Be nice, and check out our Code of Conduct.









    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f961329%2fhow-to-force-non-www-www-routing-for-subfolders-in-nginx%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Currently you only redirect from http to https. You do not have a redirect from https to https.



    You could separate the listen 443 ssl default_server and the server_name www.example.com into two separate blocks. You can use the same server block for your listen 80 default_server block.



    For example:



    server 
    listen 80 default_server;
    listen [::]:80 default_server;
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;

    return 301 https://www.schandillia.com$request_uri;


    server
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name www.example.com;

    ...



    Any request that is not to https://www.example.com and is not handled by another server block will be redirected to https://www.example.com.






    share|improve this answer



























      2














      Currently you only redirect from http to https. You do not have a redirect from https to https.



      You could separate the listen 443 ssl default_server and the server_name www.example.com into two separate blocks. You can use the same server block for your listen 80 default_server block.



      For example:



      server 
      listen 80 default_server;
      listen [::]:80 default_server;
      listen 443 default_server ssl;
      listen [::]:443 default_server ssl;

      return 301 https://www.schandillia.com$request_uri;


      server
      listen 443 ssl http2;
      listen [::]:443 ssl http2;
      server_name www.example.com;

      ...



      Any request that is not to https://www.example.com and is not handled by another server block will be redirected to https://www.example.com.






      share|improve this answer

























        2












        2








        2







        Currently you only redirect from http to https. You do not have a redirect from https to https.



        You could separate the listen 443 ssl default_server and the server_name www.example.com into two separate blocks. You can use the same server block for your listen 80 default_server block.



        For example:



        server 
        listen 80 default_server;
        listen [::]:80 default_server;
        listen 443 default_server ssl;
        listen [::]:443 default_server ssl;

        return 301 https://www.schandillia.com$request_uri;


        server
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name www.example.com;

        ...



        Any request that is not to https://www.example.com and is not handled by another server block will be redirected to https://www.example.com.






        share|improve this answer













        Currently you only redirect from http to https. You do not have a redirect from https to https.



        You could separate the listen 443 ssl default_server and the server_name www.example.com into two separate blocks. You can use the same server block for your listen 80 default_server block.



        For example:



        server 
        listen 80 default_server;
        listen [::]:80 default_server;
        listen 443 default_server ssl;
        listen [::]:443 default_server ssl;

        return 301 https://www.schandillia.com$request_uri;


        server
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
        server_name www.example.com;

        ...



        Any request that is not to https://www.example.com and is not handled by another server block will be redirected to https://www.example.com.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 3 at 19:00









        Richard SmithRichard Smith

        6,6332717




        6,6332717




















            TheLearner is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            TheLearner is a new contributor. Be nice, and check out our Code of Conduct.












            TheLearner is a new contributor. Be nice, and check out our Code of Conduct.











            TheLearner is a new contributor. Be nice, and check out our Code of Conduct.














            Thanks for contributing an answer to Server Fault!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f961329%2fhow-to-force-non-www-www-routing-for-subfolders-in-nginx%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            RemoteApp sporadic failureWindows 2008 RemoteAPP client disconnects within a matter of minutesWhat is the minimum version of RDP supported by Server 2012 RDS?How to configure a Remoteapp server to increase stabilityMicrosoft RemoteApp Active SessionRDWeb TS connection broken for some users post RemoteApp certificate changeRemote Desktop Licensing, RemoteAPPRDS 2012 R2 some users are not able to logon after changed date and time on Connection BrokersWhat happens during Remote Desktop logon, and is there any logging?After installing RDS on WinServer 2016 I still can only connect with two users?RD Connection via RDGW to Session host is not connecting

            How to write a 12-bar blues melodyI-IV-V blues progressionHow to play the bridges in a standard blues progressionHow does Gdim7 fit in C# minor?question on a certain chord progressionMusicology of Melody12 bar blues, spread rhythm: alternative to 6th chord to avoid finger stretchChord progressions/ Root key/ MelodiesHow to put chords (POP-EDM) under a given lead vocal melody (starting from a good knowledge in music theory)Are there “rules” for improvising with the minor pentatonic scale over 12-bar shuffle?Confusion about blues scale and chords

            Esgonzo ibérico Índice Descrición Distribución Hábitat Ameazas Notas Véxase tamén "Acerca dos nomes dos anfibios e réptiles galegos""Chalcides bedriagai"Chalcides bedriagai en Carrascal, L. M. Salvador, A. (Eds). Enciclopedia virtual de los vertebrados españoles. Museo Nacional de Ciencias Naturales, Madrid. España.Fotos