ng build --prod --base-href=/petclinic/ --deploy-url=/petclinic/
Create sub-directory /petclinic in default nginx directory /usr/share/nginx/html
Copy /dist sub-directory from Angular appication to /usr/share/nginx/html/petclinic
Edit nginx config (nginx.conf file in /etc/nginx/ directory)
server {
listen 80 default_server;
root /usr/share/nginx/html;
index index.html;
location /petclinic/ {
alias /usr/share/nginx/html/petclinic/dist/;
try_files $uri$args $uri$args/ /petclinic/index.html;
}
}
Reload nginx: nginx -s reload
Run app in brouser: http://server_name/petclinic/
Deploy on Apache (for Apache CentOS installation):
Build Angular application:
ng build --prod --base-href=/petclinic/ --deploy-url=/petclinic/
Create sub-directory /petclinic in default Apache directory /var/www/html
Go into Angular appication /dist sub-directory and copy all files and sub-dirs from it to /var/www/html/petclinic
Edit Apache config (/etc/https/conf/httpd.conf):
sudo vi /etc/httpd/conf/httpd.conf
Find the Directory /var/www/html> section and change the AllowOverride directive from None to All:
/etc/httpd/conf/httpd.conf
. . .
<Directory /var/www/html>
. . .
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
. . .
</Directory>
. . .
Save and exit the file and then restart Apache to apply the change:
sudo systemctl restart httpd
Create a .htaccess file in the directory /var/www/html/petclinic
sudo vi /var/www/html/petclinic/.htaccess
Add the following line to the top of the file to activate the RewriteEngine, which instructs Apache to process any rules that follow:
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ index.html
请发表评论