sudo apt update
sudo apt install wine-stable // cài wine 3.0
danh sách ứng dụng windows chạy được trên wine
https://appdb.winehq.org/
Saturday, April 4, 2020
Sunday, March 29, 2020
How To Configure Nginx as a Reverse Proxy for Apache
Why Run Nginx and Apache Together
Both nginx and apache are powerful and effective servers. Apache currently reigns as the #1 server for websites and since its public release in 2006, nginx has taken the world by storm and is now the #2 server for active sites. The reasons for each respective server’s popularity are clear: apache’s power and nginx’s speed are well known. However, both servers do have drawbacks—apache is hard on server memory, while nginx (great at static files) needs the help of php-fpm or similar modules for dynamic content.
However, one can combine the two web servers to great effect, with nginx as static web server front and apache processing the back end.
Setup
To perform the steps in this tutorial, you will need to have sudo privileges on your virtual private server.
To create a user with sudo privileges, go through the third and fourth steps of the initial ubuntu server setup tutorial
Install nginx
To start off, we need to install and configure nginx which will serve the front end of our site.
Let’s download it from apt-get:
sudo apt-get install nginx
Once it has downloaded, you can go ahead and configure the virtual host to run on the front end.
There are a few changes we need to make in the configuration.
Configure nginx
Open up the nginx configuration.
sudo nano /etc/nginx/sites-available/example
The following configuration will set you up to use nginx as the front end server. It is very similar to the default set up, and the details are under the configuration.
server {
listen 80;
root /var/www/;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080;
}
location ~ /\.ht {
deny all;
}
}
The following changes were implemented in the configuration:
- The root was set to the correct web directory
- index.php was added on the index line
- try_files attempts to serve whatever page the visitor requests. If nginx is unable, then the file is passed to the proxy
- proxy_pass lets nginx the address of the proxied server
- Finally the "location ~ /\.ht {" location block denies access to .htaccess files, if Apache's document root concurs with nginx's one
This configuration sets up a system where all extensions with a php ending are rerouted to the apache backend which will run on port 8080.
Activate the virtual host.
sudo ln -s /etc/nginx/sites-available/example /etc/nginx/sites-enabled/example
Additionally, delete the default nginx server block.
sudo rm /etc/nginx/sites-enabled/default
The next step is to install and configure apache.
Install Apache
With nginx taken care of, it’s time to install our backend, apache.
sudo apt-get install apache2
Since nginx is still not turned on, Apache will start running on port 80.
Configure Apache
We need to configure apache to take over the backend, which as we told nginx, will be running on port 8080. Open up the apache ports file to start setting apache on the correct port:
sudo nano /etc/apache2/ports.conf
Find and change the following lines to have apache running on port 8080, accessible only from the localhost:
NameVirtualHost 127.0.0.1:8080 Listen 127.0.0.1:8080
Save and Exit.
Subsequently, open up a new virtual host file, copying the layout from the default apache file:
sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example
sudo nano /etc/apache2/sites-available/example
The main issue that needs to be addressed here is that the virtual host needs to be, once again, running on port 8080 (instead of the default 80 given to nginx).
The line should look like this:
<VirtualHost 127.0.0.1:8080>
Make sure your Document Root is correct. Save and exit the file and activate that virtual host:
sudo a2ensite example
Before we start testing anything out, we need to equip apache with php. Go ahead and install it now:
sudo apt-get install php5
Restart both servers to make the changes effective:
sudo service apache2 restart
sudo service nginx restart
Finish Up
We have set up the VPS with nginx running on the front end of our site and apache processing php on the back end. Loading our domain will take us to our site’s default page.
We can check that information is being routed to apache is working by running a common php script.
Go ahead and create the php.info file:
sudo nano /var/www/info.php
Paste the following lines into that file:
<? phpinfo( ); ?>
Save and exit.
Visiting your domain/info.php should show you php info screen, and you’ll be able to see that this was handled by apache. (screenshot here)
Finally, you can see which ports are open and which application is on each one by typing in this command.
sudo netstat -plunt
Thursday, February 13, 2020
How To Install the Apache Web Server on Ubuntu 18.04
Introduction
The Apache HTTP server is the most widely-used web server in the world. It provides many powerful features including dynamically loadable modules, robust media support, and extensive integration with other popular software.
In this guide, we’ll explain how to install an Apache web server on your Ubuntu 18.04 server.
Prerequisites
Before you begin this guide, you should have a regular, non-root user with sudo privileges configured on your server. Additionally, you will need to enable a basic firewall to block non-essential ports. You can learn how to configure a regular user account and set up a firewall for your server by following our initial server setup guide for Ubuntu 18.04.
When you have an account available, log in as your non-root user to begin.
Step 1 — Installing Apache
Apache is available within Ubuntu’s default software repositories, making it possible to install it using conventional package management tools.
Let’s begin by updating the local package index to reflect the latest upstream changes:
- sudo apt update
Then, install the
apache2 package:
- sudo apt install apache2
After confirming the installation,
apt will install Apache and all required dependencies.Step 2 — Adjusting the Firewall
Before testing Apache, it’s necessary to modify the firewall settings to allow outside access to the default web ports. Assuming that you followed the instructions in the prerequisites, you should have a UFW firewall configured to restrict access to your server.
During installation, Apache registers itself with UFW to provide a few application profiles that can be used to enable or disable access to Apache through the firewall.
List the
ufw application profiles by typing:
- sudo ufw app list
You will see a list of the application profiles:
Output
Available applications:
Apache
Apache Full
Apache Secure
OpenSSH
As you can see, there are three profiles available for Apache:
- Apache: This profile opens only port 80 (normal, unencrypted web traffic)
- Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
- Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)
It is recommended that you enable the most restrictive profile that will still allow the traffic you’ve configured. Since we haven’t configured SSL for our server yet in this guide, we will only need to allow traffic on port 80:
- sudo ufw allow 'Apache'
You can verify the change by typing:
- sudo ufw status
You should see HTTP traffic allowed in the displayed output:
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Apache ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Apache (v6) ALLOW Anywhere (v6)
As you can see, the profile has been activated to allow access to the web server.
Step 3 — Checking your Web Server
At the end of the installation process, Ubuntu 18.04 starts Apache. The web server should already be up and running.
Check with the
systemd init system to make sure the service is running by typing:
- sudo systemctl status apache2
Output
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Tue 2018-04-24 20:14:39 UTC; 9min ago
Main PID: 2583 (apache2)
Tasks: 55 (limit: 1153)
CGroup: /system.slice/apache2.service
├─2583 /usr/sbin/apache2 -k start
├─2585 /usr/sbin/apache2 -k start
└─2586 /usr/sbin/apache2 -k start
As you can see from this output, the service appears to have started successfully. However, the best way to test this is to request a page from Apache.
You can access the default Apache landing page to confirm that the software is running properly through your IP address. If you do not know your server’s IP address, you can get it a few different ways from the command line.
Try typing this at your server’s command prompt:
- hostname -I
You will get back a few addresses separated by spaces. You can try each in your web browser to see if they work.
An alternative is typing this, which should give you your public IP address as seen from another location on the internet:
- curl -4 icanhazip.com
When you have your server’s IP address, enter it into your browser’s address bar:
http://your_server_ip
You should see the default Ubuntu 18.04 Apache web page:

This page indicates that Apache is working correctly. It also includes some basic information about important Apache files and directory locations.
Step 4 — Managing the Apache Process
Now that you have your web server up and running, let’s go over some basic management commands.
To stop your web server, type:
- sudo systemctl stop apache2
To start the web server when it is stopped, type:
- sudo systemctl start apache2
To stop and then start the service again, type:
- sudo systemctl restart apache2
If you are simply making configuration changes, Apache can often reload without dropping connections. To do this, use this command:
- sudo systemctl reload apache2
By default, Apache is configured to start automatically when the server boots. If this is not what you want, disable this behavior by typing:
- sudo systemctl disable apache2
To re-enable the service to start up at boot, type:
- sudo systemctl enable apache2
Apache should now start automatically when the server boots again.
Step 5 — Setting Up Virtual Hosts (Recommended)
When using the Apache web server, you can use virtual hosts (similar to server blocks in Nginx) to encapsulate configuration details and host more than one domain from a single server. We will set up a domain called your_domain, but you should replace this with your own domain name. To learn more about setting up a domain name with DigitalOcean, see our Introduction to DigitalOcean DNS.
Apache on Ubuntu 18.04 has one server block enabled by default that is configured to serve documents from the
/var/www/html directory. While this works well for a single site, it can become unwieldy if you are hosting multiple sites. Instead of modifying /var/www/html, let’s create a directory structure within /var/www for a your_domain site, leaving /var/www/html in place as the default directory to be served if a client request doesn’t match any other sites.
Create the directory for your_domain as follows:
- sudo mkdir /var/www/your_domain
Next, assign ownership of the directory with the
$USER environment variable:
- sudo chown -R $USER:$USER /var/www/your_domain
The permissions of your web roots should be correct if you haven’t modified your
unmask value, but you can make sure by typing:
- sudo chmod -R 755 /var/www/your_domain
Next, create a sample
index.html page using nano or your favorite editor:
- nano /var/www/your_domain/index.html
Inside, add the following sample HTML:
/var/www/your_domain/index.html
<html>
<head>
<title>Welcome to Your_domain!</title>
</head>
<body>
<h1>Success! The your_domain virtual host is working!</h1>
</body>
</html>
Save and close the file when you are finished.
In order for Apache to serve this content, it’s necessary to create a virtual host file with the correct directives. Instead of modifying the default configuration file located at
/etc/apache2/sites-available/000-default.conf directly, let’s make a new one at /etc/apache2/sites-available/your_domain.conf:
- sudo nano /etc/apache2/sites-available/your_domain.conf
Paste in the following configuration block, which is similar to the default, but updated for our new directory and domain name:
/etc/apache2/sites-available/your_domain.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName your_domain
ServerAlias www.your_domain
DocumentRoot /var/www/your_domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Notice that we’ve updated the
DocumentRoot to our new directory and ServerAdmin to an email that the your_domain site administrator can access. We’ve also added two directives: ServerName, which establishes the base domain that should match for this virtual host definition, and ServerAlias, which defines further names that should match as if they were the base name.
Save and close the file when you are finished.
Let’s enable the file with the
a2ensite tool:
- sudo a2ensite your_domain.conf
Disable the default site defined in
000-default.conf:
- sudo a2dissite 000-default.conf
Next, let’s test for configuration errors:
- sudo apache2ctl configtest
You should see the following output:
Output
Syntax OK
Restart Apache to implement your changes:
- sudo systemctl restart apache2
Apache should now be serving your domain name. You can test this by navigating to
http://your_domain, where you should see something like this:
Step 6 – Getting Familiar with Important Apache Files and Directories
Now that you know how to manage the Apache service itself, you should take a few minutes to familiarize yourself with a few important directories and files.
Content
/var/www/html: The actual web content, which by default only consists of the default Apache page you saw earlier, is served out of the/var/www/htmldirectory. This can be changed by altering Apache configuration files.
Server Configuration
/etc/apache2: The Apache configuration directory. All of the Apache configuration files reside here./etc/apache2/apache2.conf: The main Apache configuration file. This can be modified to make changes to the Apache global configuration. This file is responsible for loading many of the other files in the configuration directory./etc/apache2/ports.conf: This file specifies the ports that Apache will listen on. By default, Apache listens on port 80 and additionally listens on port 443 when a module providing SSL capabilities is enabled./etc/apache2/sites-available/: The directory where per-site virtual hosts can be stored. Apache will not use the configuration files found in this directory unless they are linked to thesites-enableddirectory. Typically, all server block configuration is done in this directory, and then enabled by linking to the other directory with thea2ensitecommand./etc/apache2/sites-enabled/: The directory where enabled per-site virtual hosts are stored. Typically, these are created by linking to configuration files found in thesites-availabledirectory with thea2ensite. Apache reads the configuration files and links found in this directory when it starts or reloads to compile a complete configuration./etc/apache2/conf-available/,/etc/apache2/conf-enabled/: These directories have the same relationship as thesites-availableandsites-enableddirectories, but are used to store configuration fragments that do not belong in a virtual host. Files in theconf-availabledirectory can be enabled with thea2enconfcommand and disabled with thea2disconfcommand./etc/apache2/mods-available/,/etc/apache2/mods-enabled/: These directories contain the available and enabled modules, respectively. Files in ending in.loadcontain fragments to load specific modules, while files ending in.confcontain the configuration for those modules. Modules can be enabled and disabled using thea2enmodanda2dismodcommand.
Server Logs
/var/log/apache2/access.log: By default, every request to your web server is recorded in this log file unless Apache is configured to do otherwise./var/log/apache2/error.log: By default, all errors are recorded in this file. TheLogLeveldirective in the Apache configuration specifies how much detail the error logs will contain.
Conclusion
Now that you have your web server installed, you have many options for the type of content you can serve and the technologies you can use to create a richer experience.
If you’d like to build out a more complete application stack, you can look at this article on how to configure a LAMP stack on Ubuntu 18.04.
Subscribe to:
Posts (Atom)