Prerequisites
- 1Panel installed on the server
- OpenResty running in a Docker container
- Existing site working (e.g.,
web.quickpay.wang)
Step 1: Identify the OpenResty Container Name
| |
Example output:
| |
What: Find the container name (e.g., 1Panel-openresty-sWqr) — all subsequent docker exec commands need it.
Why: 1Panel’s OpenResty runs inside Docker, so you can’t use the host’s nginx command directly. Container names may change after restart, so reconfirm before each operation.
Step 2: Create the Site Directory and Add Files
| |
What: Create a subdirectory under /opt/1panel/www/ and place your website files there.
Why: /opt/1panel/www/ maps to /www/ inside the OpenResty container. Creating a subfolder here is equivalent to creating a subpath in the web root.
Path mapping:
| Host Path | Container Path |
|---|---|
/opt/1panel/www/preview/ | /www/preview/ |
/opt/1panel/www/conf.d/ | /usr/local/openresty/nginx/conf/conf.d/ |
Step 3: Write the Nginx Configuration File
| |
What: Create a .conf file named after the domain in /opt/1panel/www/conf.d/.
Why: OpenResty’s main config includes conf.d/*.conf, so placing files there auto-loads them without modifying the main configuration.
Configuration explained:
| Directive | Meaning |
|---|---|
listen 8025 | Listen on port 8025 |
server_name preview.quickpay.wang | Match requests for this domain |
root /www/preview | Website files path inside container |
try_files $uri $uri/ =404 | Look for files in order, return 404 if not found |
Step 4: Test Configuration Syntax
| |
What: Check the configuration file for syntax errors.
Why: A misconfigured reload can stop all OpenResty services. Testing first is a mandatory safety step.
Expected output:
| |
If it fails: Check for missing semicolons, typos, or path errors, then retest.
Step 5: Reload Configuration
| |
What: Reload all configuration files to activate the new site.
Why: reload is a graceful operation that doesn’t interrupt existing connections. It’s the recommended approach for production environments.
Verify it worked:
| |
Returns 200 on success.
Step 6: Open Port (If Needed)
If the server has a firewall or cloud security group:
| |
Also add an inbound rule in your cloud console (Alibaba Cloud, Tencent Cloud, AWS, etc.) allowing TCP 8025.
Why: Even with correct Nginx config, if the port isn’t open, external requests can’t reach the server.
Access Verification
Open in browser:
| |
Complete Workflow (Copy-Paste Ready)
| |
Troubleshooting
| Problem | Cause | Solution |
|---|---|---|
nginx -t fails | Syntax error in config | Check semicolons, brackets, paths |
| Port not listening | Config not reloaded or wrong container name | Reconfirm container name and reload |
| External access fails | Firewall/security group not open | Open the corresponding port |
| 403 Forbidden | Directory permissions or missing index file | Check file permissions and directory structure |
| 404 Not Found | Wrong root path | Confirm container path is /www/xxx |