[英]Redirect root to another folder in nginx server
我對nginx非常陌生。 我以前使用過Apache,並且使用htaccess將root重定向到另一個文件夾。 現在遷移到nginx。 這是我要實現的四件事
example.com/page.php?content=file-> example.com/file我發現此代碼可以重定向,但不知道在哪里插入此代碼nginx.conf或任何其他文件?
服務器{
location = / { return 301 https://www.example.com/blog; }
}
另外,如果這些更改是在nginx.conf文件或/etc/nginx/sites-available/example.com文件中進行的,也請提出建議。
要將HTTP重定向到HTTPS通信,您可以創建另一個服務器塊以匹配傳入的HTTP和域,然后將其重寫為HTTPS服務器塊。
您將其放入哪個文件? /etc/nginx/nginx.conf
和/etc/nginx/sites-available/example.com
都應該被讀取(除非您更改了配置),所以不要緊,但是我個人將這些配置放在/etc/nginx/sites-available/example.com
因為我認為它屬於同一域。
文件: /etc/nginx/sites-available/example.com
server {
listen 80;
server_name www.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name www.example.com;
...
# your location blocks and redirects here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.