2020年1月2日 星期四

nginx 建立 Virtual Host

在 /etc/nginx/sites-available 建立一個檔案
mkdir nginx_example.com
開啟剛建立的設定檔
nano nginx_example.com
編輯並修改設定檔的內容
# configuration - nginx_example.com
#
server {
 listen 80;
 listen [::]:80;
 
 root /var/www/nginx_example.com;

 # Add index.php to the list if you are using PHP
 index index.php index.html index.htm;

 server_name example.com;

 location / {
  try_files $uri $uri/ =404;
 }

 location ~ \.php$ {
  include snippets/fastcgi-php.conf;
  fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
 }

 location ~ /\.ht {
  deny all;
 }
}
存檔後退出,建立一個軟連接
ln -s /etc/nginx/sites-available/nginx_example.com /etc/nginx/sites-enabled/nginx_example.com
重新載入 nginx
systemctl reload nginx
完成!!

沒有留言:

張貼留言